Render view from controller in ASP.NET Core

In ASP.NET Core, if you want to render a view to a string, this Stack Overflow answer makes it simple. I’ve used this to return HTML in a JSON request that also includes other data, to build an email body, and to get raw HTML to pass off to wkhtmltopdf to build PDF from HTML. […]

MVC Disable Converting Empty String to Null

Some joker decided that empty strings passed into an MVC controller should be converted to null by default. One way to avoid this is to decorate the string properties of the model class: using System.ComponentModel.DataAnnotations; public class SomeModel { [DisplayFormat(ConvertEmptyStringToNull = false)] public string SomeProperty { get; set; }} [HttpPost]public JsonResult DoSomething(SomeModel myModel) { bool […]

Versioned content in MVC

When you add a script or stylesheet to your HTML page, those requests can be cached by the browser, potentially providing outdated content to the browser. If you’re not using a bundler or anything fancy like that, then the only way to prevent this problem is to create a brand new URL whenever your script […]

Ninject in MVC5

I’ve found dozens of blogs and articles online about how to use Ninject in ASP.NET. It seems all of them are either a little outdated, or a little confusing. So I put together a basic working application for reference. This uses Visual Studio 2017, with ASP.NET MVC 5 which will run in regular IIS. I […]