RazorEngine (outside MVC) - Can I register patterns without explicitly specifying a model type?

Is it possible to register patterns without specifying the type of model?

It currently works like this (taken from: documentation ):

//Code to get template string from file xxx.cshtml into template variable
Razor.Compile(template, typeof(SomeModel), "complex");

However, I would like to precompile the templates by taking the model type definition from the directive @modelor @inheritsin the view. Is it possible?

+3
source share
2 answers

Razor.Compile It is not required to specify the type of model at compilation.

public class ActualType { public string Firstname {get;set;}}

Razor.Compile("@Model.Firstname", "outputname");
Razor.Run<ActualType>(model, "outputname");

Should work just fine for you.

@model . (http://razorengine.codeplex.com/SourceControl/list/patches), , . , MVC RazorEngine , , , MVC ( , )

v2.2, .

, , , , .

, @model template<t>. , , . , , ... .

+1

, .

modelType dynamic, .

, , .

, ; .

0

All Articles