一.工具下载:
程序集下载地址:链接: 密码: pfja
适用于visual studio2015程序集下载地址:链接: 密码: 4v7h
如果在使用vs2015等更高版本的时候出现“file not found exception cannot load system.web.razor.dll version=2.0.0”这样的错误,请换用下面附件中的程序集把旧的razoreginee.dll删掉,然后把 razorengine.net4.0.dll和system.web.razor.net4.0.dll添加到项目引用中。
二.核心代码代码封装:
public static string parserazor(httpcontext context, string cshtmlvirtualpath, object model = null) { string fullpath = context.server.mappath(cshtmlvirtualpath);//将虚拟路径转换为绝对路径 string cshtml = file.readalltext(fullpath); //将整个cshtml代码读取出来 string cachename = fullpath + file.getlastwritetime(fullpath);//返回上次写入指定文件或目录的日期和时间。 string html = razor.parse(cshtml, model, cachename); return html; } /// <summary> /// 直接将读取的cshtml代码转换完后,直接返回给客户端 /// </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); context.response.write(html); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
您可能感兴趣的文章:
- RabbitMQ单机集群搭建出现Error: unable to perform an operation on node 'rabbit1@ClusterNode1'
- DotNetty在window和linux下的性能对比
- .net core 图片合并,图片水印,等比例缩小,SixLabors.ImageSharp
- WPF简单的分页控件实现
- ASP.NET中实现中文简/繁体自动转换的类
- 前后端分离,https站点无法通过Ajax访问http资源(Mixed Content,The page at 'https://xxx.com' was loaded over HTTPS)
- layui,返回的数据不符合规范,正确的成功状态码 (code) 应为:0
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论