简体   繁体   中英

F# and ASP.NET

is it possible to write ASP.NET (MVC) applications with F# code? 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#.

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. (F# doesn't have a ASP.NET project type yet.)

The benefits are the same as usual -- everything F# provides. 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. 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. Also, IntelliSense doesn't work there. So, for the ASPX part, we used C#. Not a big deal, as that's just usually wiring up the model to the view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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