문제

I have a syntax problem: I would like to put a condition in my controller. In C#, my condition is: if (Request.Files["FileUpload"].ContentLength > 0)

I can't succeed to translate in F#, any suggestions?

My code:

namespace FsWeb.Controllers

open System.Web.Mvc
open System
open System.Web 

[<HandleError>]

type HFAnalysisController() = 
    inherit Controller()

    member this.HFAnalysis () =
     this.View() :> ActionResult

    member this.Importexcel() = 
     // C# // if (Request.Files["FileUpload1"].ContentLength > 0)
도움이 되었습니까?

해결책

I suspect the question is about how to get a dictionary value. In F# indexed properties can't be called the same way as in C#. The Item[] member has to be called explicitly:

this.Request.Files.["FileUpload1"].ContentLength

and you could write something like:

member this.ImportExcel() =
    if this.Request.Files.["FileUpload1"].ContentLength > 0 then
        ...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top