I’m looking to output some HTML to a web page using F#. Any ideas?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To give some specific “HOWTO”, I tried creating a simple ASP.NET MVC application that implements the key parts in F#. As noted in the referenced answer, the best way to use F# for web development is to create a C# web application and move all the types that implement the actual behavior to an F# library.
Although it may be possible to create directly F# web project, there are many limitations (e.g. not perfect intellisense and possibly other issues), so managing the
aspxfiles in C# is probably a better idea.Here is what I did (using Visual Studio 2010):
HomeController.csfile inControllers, which contains functionality for the homepage (loading of data etc.) You can delete the file – we’ll re-implement it in F#.System.Web.Mvc.dlland others that are referenced by this one (the F# compiler will tell you which ones you need).Module1.fs– this implements the originalHomeController, which used to be written in C#.The source code looks like this:
This is simply a re-implementation of the original C# code (creating a single class). I used the original C# namespace, so that the MVC framework can easily find it.
The file
Views\Home\Index.aspxfrom the C# project defines the user-interface and uses the data that you set to theViewDatadictionary from your F# project.This “HOWTO” shows how to use F# to write ASP.NET MVC application, but the steps to create an ordinary WebForms application would be essentially the same – create a C# web application and move the implementing classes to F# library, which will be referenced from the C# web application (which won’t actually contain much C# code).