Asp.Net MVC5 with F#

Learn ASP.NET MVC5 with F# using pure F# templates. Explore syntax mapping between C# and F# with functional programming examples.

2 min read 297 words

Thanks to Danial Mohl, getting started with ASP.NET MVC5 is pretty easy. He had put tremendous effort into making different kinds of templates, even starting from MVC3 till now.

Old templates had two projects: one in C# and one in F#. C# had all the JavaScript, HTML, CSS, and stuff, while F# had the coding part.

But with time passing and version updates, now we have pure F# templates. A single F# project has code, JavaScript, cshtml, HTML, CSS—everything. It's far more fun and easy to get started with. At the end of the day, F# is all about compressing code. Doing more with less code.

Scala people, Play is almost the same as the MVC framework. If you're following along, the code will be almost the same. I will still try to put code snippets wherever possible.

So, if you haven't downloaded the template yet, please check out my previous post—the first one in the series—and download the template. Once installed, you're up and running to write some MVC code.

I am assuming that people trying this are quite familiar with MVC and other concepts.

First, I will do a one-to-one mapping between C# and F# code, just to get familiar with the syntax. Then I'll move to optimized code to make it more functional.

Side Note: If you don't have Visual Studio Pro or higher, don't worry. Templates work with Express versions as well. As per the latest release, F# is now primarily supported by Desktop and Web Express versions.

Install the template, create a new project with MVC5 and Web API options, hit F5, and you're done. You're up and running.

Feeling great?! It's just started. roller coaster ride

Frequently Asked Questions

What is the main difference between old and new F# ASP.NET MVC templates?

Old templates were split into two projects: a C# project for frontend (JavaScript, HTML, CSS) and an F# project for backend code. New pure F# templates combine everything into a single F# project, including code, JavaScript, cshtml, HTML, and CSS, making it easier to get started.

Do I need Visual Studio Pro to use F# ASP.NET MVC5 templates?

No, you don't need Visual Studio Pro. F# templates work with Express versions as well, including Desktop and Web Express versions according to the latest release.

What are the benefits of using F# for ASP.NET MVC development?

F# is designed around compressing code and doing more with less, making it more fun and easier to write concise applications. It allows you to write complete MVC applications in a single functional language, from backend logic to frontend markup.

How do I get started with ASP.NET MVC5 in F#?

First, download the F# MVC5 template (available from Daniel Mohl's resources). Install the template, create a new project with MVC5 and Web API options, then press F5 to run your application. You'll immediately have a working MVC project.

Will Scala developers find F# ASP.NET MVC similar to their experience?

Yes, F# ASP.NET MVC is similar to Play framework for Scala developers. The code structure and many concepts will be almost identical, making it relatively easy for Scala developers to transition to F# MVC development.

Share this article