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) 通用的报错页面 为了防止忘了控制重载,封装成一个通用的方法
原文:https://www.cnblogs.com/sessiexu/p/14596568.html