Generated Razor Files Don't Work After MVC4 Upgrade - razor

After upgrading a working MVC 3 solution with Razor views to the MVC 4 beta, I get the message "} expected" from files called App_Web_2x0hrczu.0.cs and App_Web_supamddr.3.cs. They're generated files, obviously, but they appear to refer to a partial view (a .cshtml). Everything used to work, so I'm confused! Any ideas?

Related

Razor views custom scaffolding in .NET 6

Before upgrading my web application to .NET 6 a was able to scaffold Razor views with custom templates located in ProjectRoot/Templates/ViewGenerator as shown in this image. This allowed me to override default templates. After upgrading to .NET6, VS2022 is using default templates to generate these views. I tried to find some info about the new path it's expecting but i had no luck. Any help is really appreciated.

ServiceStack Razor Intellisense not working in SelfHost

I have ServiceStack.Razor referenced.
Following razor file works great:
#model ServiceStack.Host.Operation
#Model.Name
but IntelliSense (and R# code analysis) shows error: "Cannot resolve symbol 'model'"
Referencing Microsoft.AspNet.Mvc makes Intellisense work, but Razor pages are not compiled.
This is because ServiceStack.Razor contains System.Web.Razor assembly version 3.0.0 and Microsoft.AspNet.Mvc requires a 3.2.3, one is overwritten by other and assembly load exceptions occur.
Tried to follow this answer:
ServiceStack turn on Razor intellisense support without MVC
and add Web.config but this gives me different error:
"Cannot access private field 'model' here"
How to make Intellisense work without breaking application?
Unfortunately VS.NET 2015 designer doesn't properly support editing Razor pages in Self-Host (i.e. non ASP.NET Projects) so you wont be able to get rid of all the designer errors, although you can minimize the issues by first adding a Web.config with the Razor configuration, here's a Web.config template you can use, you'll need to replace $safeprojectname$ with the namespace of your project. The Web.config have no effect to the behavior of non Web projects, it's just use to provide hints to VS.NET intellisense which is coupled to ASP.NET Web projects.
Instead of #model you'll want to use the more explicit:
#inherits ViewPage<ServiceStack.Host.Operation>
These both do the same thing, but the designer is happier with the explicit #inherits.

Telerik Script Registrar Error After Upgrading to ASP.NET MVC 4 Developer Preview

I recently installed the ASP.NET MVC 4 Developer Preview (which Microsoft says can be run side by side with other projects written in MVC 3 and not affect them).
When I proceeded to run a MVC 3 application which uses the Telerik MVC Extensions (version 2011.3.1115.340) I received an error with the razor engine:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1593: Delegate 'System.Action' does not take 1 arguments
Here is the razor source code:
#{ Html.Telerik().ScriptRegistrar().OnDocumentReady(
#<text>
$('a[title]').poshytip({
className: 'tip-yellowsimple',
alignTo: 'target',
alignX: 'center',
alignY: 'bottom',
offsetY: 5,
slide: false,
showTimeout: 0
});
</text>);
How can I resolve this?
Resolution Update
The following info from the release notes worked for me:
Installing ASP.NET MVC 4 Developer Preview breaks ASP.NET MVC 3 RTM
applications. ASP.NET MVC 3 applications that were created with the
RTM release (not with the ASP.NET MVC 3 Tools Update release) require
the following changes in order to work side-by-side with ASP.NET MVC 4
Developer Preview. Building the project without making these updates
results in compilation errors. Required updates In the root Web.config
file, add a new entry with the key webPages:Version and
the value 1.0.0.0.
In Solution Explorer, right-click the project name and
then select Unload Project. Then right-click the name again and select
Edit ProjectName.csproj. Locate the following assembly references:
Replace them with the following:
Save
the changes, close the project (.csproj) file you were editing, and
then right-click the project and select Reload.
Perhaps the issue is related to ASP.NET MVC 4 developer preview.
Take a look at the ASP.NET MVC 4 Release notes, specifically the section below:
Installing ASP.NET MVC 4 Developer Preview breaks ASP.NET MVC 3 RTM applications

How to Render content include razor syntax in asp.net mvc 3

In my database there is a record which include some razor syntax like that "Hello #Model.Name, Wellcome ..." When I get this record to the view how can I render this model property ?
Thanks,
There are many ways.
Pulling a View from a database rather than a file
http://razorengine.codeplex.com
http://ibashir.blogspot.com/2010/11/razor-parser-without-mvc.html
http://blog.andrewnurse.net/2010/07/22/UsingTheRazorParserOutsideOfASPNet.aspx
I'm biased towards the RazorEngine from codeplex it's been used in the Mini-Profiler from the developers of this very site.

Upgraded to MVC3 Beta, Razor views generate a different base class than a newly created project

I have been working on a website using MVC Preview 1 since it came out. Now that beta is out, I have updated my system to beta.
There is not alot of help out there for upgrading from Preview 1 to beta, and just rebuilding caused a lot of problems. What I have done so far:
1) Copied the web.config from a new MVC3 Beta project (to get the correct sections and values).
2) Added references to System.Web.Helpers and System.Web.WebPages, so that my references would match the newly created project.
3) Changed all my #import to #model as per the new format.
The problem I am getting, is that the views in the existing project, are being derived off of System.Web.Web.Pages and those in the new project are being derived off System.Web.Mvc.WebViewPage<>.
What am I missing that would be causing this base class issue.
You also need to copy the /views/web.config from a new Mvc 3 project - its where the base page class is defined