21

is it possible to write ASP.NET (MVC) applications with F# code? If yes, how? What possible benefits would this provide?

Thanks.

pistacchio
  • 56,889
  • 107
  • 278
  • 420

1 Answers1

19

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.

MichaelGG
  • 9,976
  • 1
  • 39
  • 82
  • 1
    even the google indexed version of your blog is broken :-( (404) – Simon_Weaver Jul 18 '09 at 19:20
  • Oh crap. Thanks for pointing that out. Must be dasblog, IIS7, and me screwing up. It's the first article here though: http://www.atrevido.net/blog/ – MichaelGG Jul 20 '09 at 23:14
  • 1
    Thanks for letting me know Simon. Got it fixed. IIS7 apparently doesn't like plus signs in URLs for security. Had to disable that checking ("double escaping"). – MichaelGG Jul 20 '09 at 23:44