简体   繁体   中英

Razor parser to read .cshtml files

Like we have HtmlAgilityPack dll to read .aspx pages and we can get all the script/style references using HtmlNodeCollection class and methods inside in the dll, How can we get all the script/style references in .cshtml pages in MVC using Razor parser.

I have read about Razor Parser being an option to read .cshtml pages, but I have no idea about what it actually is? Please provide complete details on how it works, how it reads all the script/style reference syntaxes in .cshtml, what Razor parser actually is, any kind of information leading to the solution of my question is most welcome.

Using HtmlAgilityPack, I have below lines of code to read script/style references in .aspx pages:

HtmlNodeCollection bodyNode_Script = doc.DocumentNode.SelectNodes("//script");
HtmlNodeCollection bodyNode_Style = doc.DocumentNode.SelectNodes("//link");

Thanks in advance.

The Razor parser parses Razor Syntax and converts it to C# executable code. It is not designed to do the same work as the HtmlAgilityPack. If you want to get the script and style references in a rendered .cshtml file, you would use the HtmlAgilityPack for that in the same way as you would with .aspx files (or .php, .html, .jsp etc files).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM