在MVC3中,如果在任意类中渲染一个视图? 本帖最后由 WDandan 于 2012-11-13 17:27:34 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class C{ public static string RenderHeader(string view, objec m){ return "<div>ojlovecd</div>"; }}然后在视图调用的时候:@C.RenderHeader("",null); 谢谢关注,但是,貌似不太对了,你完全无视的我的视图文件header.cshtml了我的意思是说,将视图header.cshtml渲染出来。 OK,我找到了解决办法,不过,觉得代码不够优雅,要在页面上传递Html属性,代码如下:public static MvcHtmlString RenderHeader(HtmlHelper helper, List<string> lst) { return PartialExtensions.Partial(helper, "~/views/header.cshtml", lst); } 1、实现一个类继承自IViewEngine2、在Global里面添加自定义的IViewEngine, ViewEngines.Engines.Add(viewEngine) 通过调用Action加载,例: public ActionResult RenderHeader() { return PartialView("_header");//_header.cshtml }要加载的View页面调用:@Html.RenderAction("RenderHeader", "controllerName") jqeury在用户控件异步提交数据求一个解决方案、 HyperLink事件处理 datalist动态添加数据 asp.net2.0窗体滚动层 如何判断来源网站的url编码是UTF-8还是GB2312编码类型 获取数据库的月,日 大家帮我看看这个动态生成的button怎么实现不了点击事件 判断不能为空值,否则弹出提示框 呕心盼正则表达式生成工具Regulator 执行存储过程,无法获得output返回参数 ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.5.28]错误 VS2008 .ASPX页面设计视图打不开
public static string RenderHeader(string view, objec m){
return "<div>ojlovecd</div>";
}
}然后在视图调用的时候:@C.RenderHeader("",null);
谢谢关注,但是,貌似不太对了,你完全无视的我的视图文件header.cshtml了
我的意思是说,将视图header.cshtml渲染出来。
public static MvcHtmlString RenderHeader(HtmlHelper helper, List<string> lst)
{
return PartialExtensions.Partial(helper, "~/views/header.cshtml", lst);
}
2、在Global里面添加自定义的IViewEngine,
ViewEngines.Engines.Add(viewEngine)
{
return PartialView("_header");//_header.cshtml
}要加载的View页面调用:@Html.RenderAction("RenderHeader", "controllerName")