C#到F#:Request.Files [“FileUpload1”]。ContentLength

时间:2014-03-27 16:29:38

标签: f# c#-to-f#

我有一个语法问题:我想在我的控制器中添加一个条件。在C#中,我的条件是:if (Request.Files["FileUpload"].ContentLength > 0)

我无法成功翻译F#,有什么建议吗?

我的代码:

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)

1 个答案:

答案 0 :(得分:3)

我怀疑问题是关于如何获取字典值。在F#中的索引属性can't be called the same way和C#中一样。必须明确调用Item[]成员:

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

你可以这样写:

member this.ImportExcel() =
    if this.Request.Files.["FileUpload1"].ContentLength > 0 then
        ...