首页 > Web开发 > 详细

ASP.Net MVC View 查找

时间:2021-03-30 16:14:02      阅读:13      评论:0      收藏:0      [点我收藏+]

1.return view()会查找Views的Controller名字的ACtion的名字的cshtml
2.return View("Action1"),查找Views的Conctroller名字下“Action.cshtml”,如果找不到则到特殊的Shared文件夹下找“Action.cshtml”
3.return View("Action1")中如何传递model?return View("Action1",model)。
陷阱:如果model传递的是string类型,则需要return View("Action1",object(str))为什么?看一下重载
protected internal ViewResult View(string viewName, object model);
protected internal ViewResult View(string viewName, string masterName);//第二个string参数是母版页或模板的名字
注意return View("Action1") 不是重定向,浏览器和服务器之间只发生了一次交互,地址栏依旧是Action的地址。这和重定向return Redict("Index/Action1")不一样
应用:执行报错 return View("Error",(object)msg) 通用的报错页面 为了防止忘了控制重载,封装成一个通用的方法

ASP.Net MVC View 查找

原文:https://www.cnblogs.com/sessiexu/p/14596568.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!