Quantcast
Channel: RazorGenerator Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 525

Commented Issue: Error when use "DisplayTemplates\PersonViewModel.cs" and "PersonViewModel.cshtml" (Same name) [103]

$
0
0
I followed exactly the steps described in this post.
http://stacktoheap.com/blog/2013/01/19/precompiling-razor-views-in-asp-dot-net-mvc-3/

But the error is displayed below

> ASP.NET runtime error: There is no build provider registered for the extension '.cshtml'. You can register one in the <compilation><buildProviders> section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.


__What am I doing wrong?__
Comments: I had this same issue when trying to use DisplayTemplates for DateTime properties and here's how I fixed it: Recreate Issue: Create a DateTime.cshtml file in the DisplayTemplates folder: ``` @model DateTime @MvcHtmlString.Create(Model.Date.ToShortDateString()) ``` Try to compile and you'll receive errors: '(AssemblyName).Views.Shared.DisplayTemplates.DateTime' does not contain a definition for 'Date' and no extension method 'Date' accepting a first argument of type '(AssemblyName).Views.Shared.DisplayTemplates.DateTime' could be found. Why this is happening: Because the view page is getting compiled and has the same name as the model, the compiler tries to use the compiled view page as the model for itself. If you look carefully at the error you'll see that it's trying to access the .Date property of the compiled DateTime view, which will throw an error because it doesn't exist. How to fix it so that the right model is used: Explicity type out the namespace for the model that you want to use: ``` @model System.DateTime <- Instead of just DateTime, give the full namespace @MvcHtmlString.Create(Model.Date.ToShortDateString()) ``` This will now compile as expected.

Viewing all articles
Browse latest Browse all 525

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>