SoFunction
Updated on 2025-03-10

A brief introduction to the Razor template engine

1. Tool download:

Assembly download address: Link:/s/1hsGJV5yPassword: pfja

Applicable to visual studio2015 assembly download address: Link:/s/1nvn31ILPassword: 4v7h

If you appear when using VS2015 and other higher versionsFile not Found Exception Cannot Load Version=2.0.0”For such an error, please use the assembly in the following attachment to delete the old one, and then add RazorEngine.NET4. and .Net4. to the project reference.

2. Core code encapsulation:

public static string ParseRazor(HttpContext context,
   string csHtmlVirtualPath, object model = null)
  {
   string fullpath = (csHtmlVirtualPath);//Convert virtual path to absolute path   string cshtml = (fullpath); //Read the entire cshtml code   string cacheName = fullpath + (fullpath);//Returns the date and time of the last time I wrote to the specified file or directory.   string html = (cshtml, model, cacheName);
   return html;
  }
  /// <summary>
  /// After converting the read cshtml code directly, it will be returned to the client  /// </summary>
  /// <param name="context"></param>
  /// <param name="csHtmlVirtualPath"></param>
  /// <param name="model"></param>
  public static void OutputRazor(HttpContext context,
   string csHtmlVirtualPath, object model = null)
  {
   string html = ParseRazor(context, csHtmlVirtualPath, model);
   (html);    
  }  

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.