Does "the renderpage method calls in generated output" call the generated output in partial view?

Jul 30, 2012 at 12:47 PM

I used razorgenerator with the input below..

@RenderPage(

 

"~/Views/Shared/_LogIn.cshtml"

)

 and output is ...

Write(RenderPage(

"~/Views/Shared/_LogIn.cshtml"

));

I wonder if the renderpage method in the output processes the view in the precompiled view?

 

Coordinator
Jul 30, 2012 at 12:55 PM

Yes, if the _LogIn view is precompiled and you have the engine installed, it should be using that.

Jul 30, 2012 at 1:14 PM

if view filename starting with underscore , classname is without underscore.Does partial view named starting with underscore "_" cause a problem?

Coordinator
Jul 30, 2012 at 3:26 PM

Not really. We simply strip the underscore to avoid compilation warnings. But the lookup depends on the original name of the file. If you look at the compiled file, the generated type should have an attribute that says what the virtual path of the file is.

Jul 31, 2012 at 12:31 PM

I run the razorgenerator custom tool on _ViewStart.cshtml, and the error below occured.. Do I have to exclude that file?

 

System.InvalidCastException: Unable to cast object of type myproject.Web.View.Views.ViewStart' to type 'System.Web.WebPages.StartPage'.

at System.Web.WebPages.StartPage.GetStartPage(WebPageRenderingBase page, String fileName, IEnumerable`1 supportedExtensions)

at CopyTaste.RazorGenerator.PrecompiledMvcView.Render(ViewContext viewContext, TextWriter writer) in c:\myproject.RazorGenerator\PrecompiledMvcView.cs:line 67

at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)

 

..line 67...

 

 

 

 

if

 

(this

.RunViewStartPages)

{

startPage =

StartPage.GetStartPage(webViewPage, "_ViewStart"

, ViewStartFileExtensions);

}

Coordinator
Jul 31, 2012 at 12:40 PM

What does your generated ViewStart class look like? It should look like this, where it extends ViewStartPage (which would make the cast work).

Jul 31, 2012 at 12:44 PM

Solved when I changed the base class of _ViewStart.cshtml output from WebViewPage to ViewStartPage. Odd..ViewStart must be derived from ViewStartPage..I think RazorGenerator must handle it..Is it true?

Jul 31, 2012 at 12:46 PM

 

 

 

 

 

 

 

[System.CodeDom.Compiler.

 

GeneratedCodeAttribute("CustomRazorGenerator", "1.5.0.0"

)]

[System.Web.WebPages.

 

PageVirtualPathAttribute("~/Views/_ViewStart.cshtml"

)]

 

 

public class ViewStart : System.Web.Mvc.

WebViewPage

{

 

 

public

ViewStart()

{

}

 

 

public override void

Execute()

{

 

#line

 

 

1 "..\..\Views\_ViewStart.cshtml"

 

 

 

#line

 

 

default

#line

 

 

hidden

}

}

Coordinator
Jul 31, 2012 at 1:09 PM

The seems to imply that RazorGenerator is not treating your ViewStart page as a start page, and instead treats it as a regular view.

Do you see this if you start from a clean MVC project (internet app) and turn on RazorGenerator on all views? Or does it only happen with your specific project? If the latter, please try to isolate what might be different there.

Jul 31, 2012 at 1:24 PM

with nuget razorgeneratotor version, it works ..but custom razorgenerator tool with some changes does not work properly..my changes are minor for minification, what might cause it?

Jul 31, 2012 at 2:31 PM

Is RazorGenerator 1.4.3 compatible with VS2010?

Coordinator
Jul 31, 2012 at 3:51 PM

Yes, 1.4.3 should work fine with both VS2010 and VS2012. If you're only having problem with your custom modified build, then you're probably going to have to debug it to see what's going on. But if you can use the official build, it's obviously simpler! :)

Aug 1, 2012 at 8:11 AM

I debugged the core project..The code below sets the base type properly, but the generated code does not contain it as base type for _ViewStart.html!

 

public MvcCodeGenerator(string className, string baseClass, string rootNamespaceName, string sourceFileName, RazorEngineHost

host)

:

base

(className, rootNamespaceName, sourceFileName, host)

{

 

string

baseType;

 

if

(IsSpecialPage(sourceFileName))

{

baseType =

typeof(ViewStartPage

).FullName;

}

 

else

{

baseType = baseClass +

'<' + DefaultModelTypeName + '>'

;

}

SetBaseType(baseType);

}

 

private bool IsSpecialPage(string

path)

{

 

string fileName = Path

.GetFileNameWithoutExtension(path);

 

return fileName.Equals(ViewStartFileName, StringComparison

.OrdinalIgnoreCase);

}

 

private void SetBaseType(string

name)

{

 

var baseType = new CodeTypeReference

(name);

GeneratedClass.BaseTypes.Clear();

GeneratedClass.BaseTypes.Add(baseType);

}

Aug 1, 2012 at 11:49 AM

Thank you so much..Solved with custom mvc code generator.. and setbasetype moved into it..