Razor.Parse alternative

▼魔方 西西 提交于 2020-01-02 06:39:11

问题


We have a default value for a textbox that is coming from a database and it is

@UserSession.NumberOfPeople

This is currently parsed by using

string value = Razor.Parse(Model.DefaultValue)

Which returns me the string value from that variable

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")

Or do I need to create some sort of template or install a nuget package for this?


回答1:


You could use RazorEngine and simply use your string as the template:

Engine.Razor.RunCompile(Model.DefaultValue, "templateKey", null, Model);

NOTE: For the RunCompile to accept a string as a template you need to use RazorEngine.Templating (@using RazorEngine.Templating in your view).



来源:https://stackoverflow.com/questions/48501346/razor-parse-alternative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!