.NET Core - MVC

Observations about .NET Core, MVC and converting YetaWF from ASP.NET MVC5 to .NET Core MVC. The new .NET Core has great new features. Getting there from an existing MVC 5 app is HARD!

Custom Razor Views cannot inherit RazorPage<T>

02/23/2017

This was almost a showstopper.

Our views would not compile with ASP.NET Core MVC. Every single one got this error:

Property 'ViewData' is of type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[[YetaWF.Modules.Text.Controllers.TextModuleController+TextModelDisplay, YetaWF.Text, Version=1.1.1.0, Culture=neutral, PublicKeyToken=null]]', but this method requires a value of type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
Parameter name: viewContext
This is in fact a bug (see https://github.com/aspnet/Mvc/issues/5397). There are a few workarounds, but they are impractical for anything but trivial projects. For details see the issue report at https://github.com/aspnet/Mvc/issues/5397.

While I hope this will be addressed in a future version of ASP.NET Core MVC, we obviously don't want to just wait for that.

Instead, YetaWF 2.0 will distribute its own, custom MVC assemblies which correct this problem for now. Unfortunately this is a solution that is very specific to YetaWF and can't be applied as a general solution.

We started using an updated ASP.NET Core MVC "dev" version 1.2 2.0 (Edit: renamed 2.0 end of April 2017), which addresses the problem (mostly). It does require some extra code on our part in YetaWF, but it preserves source compatibility for all our views. For the time being we can include this (unmodified) dev version of MVC and hopefully the official 2.0 (scheduled for Q3 2017) will solve all our issues.

Update 5/20/2017: This was later moved to issue https://github.com/aspnet/Mvc/issues/6291
Update 11/30/2018: The issue was closed without resolution - YetaWF no longer uses Razor views so this is no longer relevant to us.

No Comments

Be the first to add a comment!

Add New Comment

Complete this simple form to add a comment to this blog entry.