Razor.Parse替代 [英] Razor.Parse alternative
问题描述
我们有一个来自数据库的文本框的默认值,它是
We have a default value for a textbox that is coming from a database and it is
@UserSession.NumberOfPeople
当前使用
string value = Razor.Parse(Model.DefaultValue)
哪个会从该变量返回我的字符串值
Which returns me the string value from that variable
但是,由于Razor.Parse
现在已过时,我正在研究使用Engine.Razor.Compile
的另一种方法,但是我似乎找不到不需要模板的重载
However as Razor.Parse
is now obsolete, I was looking into an alternative way using Engine.Razor.Compile
but I can't seem to find an overload that isn't requiring a template
有没有一种方法可以按原样解析值
Is there a way of just parsing the the value as it is
string value = Razor.Parse("@UserSession.NumberOfPeople")
还是我需要为此创建某种模板或安装nuget包?
Or do I need to create some sort of template or install a nuget package for this?
推荐答案
您可以使用 RazorEngine
并简单地使用您的字符串作为模板:
You could use RazorEngine
and simply use your string as the template:
Engine.Razor.RunCompile(Model.DefaultValue, "templateKey", null, Model);
注意:要使RunCompile
接受string
作为模板,您需要使用RazorEngine.Templating
(视图中的@using RazorEngine.Templating
).
NOTE: For the RunCompile
to accept a string
as a template you need to use RazorEngine.Templating
(@using RazorEngine.Templating
in your view).
这篇关于Razor.Parse替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!