简体   繁体   English

F#和ASP.NET

[英]F# and ASP.NET

is it possible to write ASP.NET (MVC) applications with F# code? 是否可以使用F#代码编写ASP.NET(MVC)应用程序? If yes, how? 如果有,怎么样? What possible benefits would this provide? 这会带来哪些好处?

Thanks. 谢谢。

Yes. 是。 In fact, we're just finishing an app using ASP.NET MVC and NHibernate, with F#. 事实上,我们只是使用带有F#的ASP.NET MVC和NHibernate来完成一个应用程序。

It's pretty easy: create a C# ASP.NET MVC app, then create an F# library, and put all your controllers in the F# library. 这很简单:创建一个C#ASP.NET MVC应用程序,然后创建一个F#库,并将所有控制器放在F#库中。 (F# doesn't have a ASP.NET project type yet.) (F#还没有ASP.NET项目类型。)

The benefits are the same as usual -- everything F# provides. 好处与往常一样 - F#提供的一切。 Of particular note is how short the controller code becomes. 特别值得注意的是控制器代码有多短。 The type inference is just excellent. 类型推断非常好。

If you want to use F# record types with the MVC binder, you'll need a bit of helper code. 如果要将F#记录类型与MVC绑定器一起使用,则需要一些辅助代码。 I wrote about it here . 在这里写了这篇文章

However, with the 1.9.6.16 release, The F# ASPNetCodeDomProvider has some bugs, making it unsuitable for use in the ASPX pages. 但是,在1.9.6.16版本中,F#ASPNetCodeDomProvider存在一些错误,使其不适合在ASPX页面中使用。 Also, IntelliSense doesn't work there. 此外,IntelliSense无法在那里工作。 So, for the ASPX part, we used C#. 因此,对于ASPX部分,我们使用了C#。 Not a big deal, as that's just usually wiring up the model to the view. 没什么大不了的,因为通常只是将模型连接到视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM