Below you will find pages that utilize the taxonomy term “ASP.NET MVC”
February 18, 2021
Adding Razor cshtml view runtime re-compilation to a ASP.NET Core 5.0 app after creating it
I recently came across an interesting issue where after starting a new ASP.NET Core 5.0 .NET 5 project using the “ASP.NET Core Web App (Model-View-Controller)” template did not include the ability to update .cshtml Razor files without recompiling and restarting the whole app. There is a checkbox to “Enable Razor Runtime Compilation” during project setup but it’s easy to miss and tricky to add afterwards if you don’t know what you are looking for.
May 30, 2013
ASP.NET MVC Basics Part 2: ViewModel to Model Mapping and Editing
In Part 1, I walked through creating a simple form with a backing ViewModel and Validation. In Part 2, I’ll walk through creating a backing Model and Edit functionality.
To start off from here, load up the code from part1: https://github.com/edandersen/mvcformtutorial/tree/part1
The final code for Part 2 will be uploaded here: https://github.com/edandersen/mvcformtutorial/tree/part2
Model Mapping flow When editing a ViewModel, we need to prepopulate the view with real data from a domain model.
May 28, 2013
ASP.NET MVC Basics Part 1: View Model binding
I’m going to walk through the basics of Form submission with ASP.NET MVC, showing some best practices. This set of tutorials will be useful for developers moving away from ASP.NET WebForms into ASP.NET MVC or even Rails developers curious about how we do things in .NET.
You can download the code for Part 1 at: https://github.com/edandersen/mvcformtutorial/tree/part1
Form submission flow If you have come from WebForms, you’ll be used to being able to pull form values out in the code behind by simply referencing variables in your code behind.
February 17, 2013
Adding a Dynamic Robots.txt file to an ASP.NET MVC site
Robots.txt is required to allow search engines to properly index your site, and more importantly not index it. If you have a public-facing staging or preliminary site that you don’t want to show up in Google results, you need to make sure that it returns the correct robots.txt with the
Disallow: / line to prevent indexing. However, manually adding robots.txt files to staging and production environments as a manual process can be improved with the process below – the same code can serve up a locked down robots.