Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Razor template engine

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to use the Razor template engine", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use the Razor template engine" this article.

one。 Tool download:

Assembly download address: link: http://pan.baidu.com/s/1hsGJV5y password: pfja

Applicable to visual studio2015 assembly download address: link: http://pan.baidu.com/s/1nvn31IL password: 4v7h

If an error such as "File not Found Exception Cannot Load System.Web.Razor.dll Version=2.0.0" occurs when using a later version such as VS2015, delete the old RazorEginee.dll with the assembly in the attachment below, and then add RazorEngine.NET4.0.dll and System.Web.Razor.Net4.0.dll to the project reference.

two。 Core code encapsulation:

Public static string ParseRazor (HttpContext context, string csHtmlVirtualPath, object model = null) {string fullpath = context.Server.MapPath (csHtmlVirtualPath); / / convert the virtual path to the absolute path string cshtml = File.ReadAllText (fullpath); / / read the entire cshtml code string cacheName = fullpath + File.GetLastWriteTime (fullpath); / / return the date and time when the specified file or directory was last written. String html = Razor.Parse (cshtml, model, cacheName); return html;} / directly convert the read cshtml code and return it directly to the client / public static void OutputRazor (HttpContext context, string csHtmlVirtualPath, object model = null) {string html = ParseRazor (context, csHtmlVirtualPath, model); context.Response.Write (html) } these are all the contents of the article "how to use the Razor template engine". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report