概述
1RenderView
RenderView的重载:
RenderView(string viewName);
RenderView(string viewName, object viewData);
RenderView(string viewName, string masterName);
RenderView(string viewName, string masterName, object viewData);
我们常用的当然就是第一种
第二种RenderView(string viewName, object viewData);是在显示view时附加一个ViewData
如:
RenderView("Index", new
{
name = "123",
sex = 123
});
我们就可以在相应的View(即Index.aspx)中调用<%=ViewData["name"]%>来得到它的值
RenderView(string viewName, string masterName);
则是除了Viewname之外还指定了母板页
2.Redirect方法跳转页面到其它的Controller/Action
![](http://www.cnblogs.com/images/outliningindicators/none.gif)
![](http://www.cnblogs.com/images/outliningindicators/none.gif)
![](http://www.cnblogs.com/images/outliningindicators/none.gif)
在这里前两种都没有什么好说的RedirectToAction("About","Home");就是一种写法
主要是第三种重载
用户可以这样写
![](http://www.cnblogs.com/images/outliningindicators/none.gif)
![](http://www.cnblogs.com/images/outliningindicators/none.gif)
![](http://www.cnblogs.com/images/outliningindicators/none.gif)
![](http://www.cnblogs.com/images/outliningindicators/none.gif)
这样就可以完成页面跳转
当然,也可以使用传统的Response.Redirect来完成页面的跳转
3.Action 中 return View()的理解
也就是ActionResult,这里return View()其实就是返回html格式的内容给页面显示,而ActionResult是有很多类型的:
· View() – 返回一个 ViewResult.
· PartialView() – 返回一个 PartialViewResult.
· RedirectToAction() – 返回一个 RedirectToRouteResult .
· Redirect() – 返回一个 RedirectResult.
· Content() – 返回一个 ContentResult.
· Json() – 返回一个 JsonResult.
· File() – 返回一个 FileResult.
· JavaScript() – 返回一个 JavaScriptResult.
· RedirectToRoute() – 返回一个 RedirectToRouteResult.
解释:
· ViewResult – 表示一个普通的 ASP.NET MVC view.
· PartialViewResult – 表示一个ASP.NET MVC view的一个片段.
· RedirectResult – 表示重定向到另外一个controller action 或者 URL.
return RedirectToAction("Index"); return RedirectToAction(“Index”, “Product”);return RedirectToAction(“Details”, new {id=53});· ContentResult – 表示发送一些基本的类型的内容给浏览器,只要是.net的基本类型都可以 比如:string,int,double等等
public string SayHello()
{
return "Hello";
}· JsonResult – 返回一个Json类型给浏览器
public ActionResult List()
{
var quotes = new List<string>
{
"Look before you leap",
"The early bird gets the worm",
"All hat, no cattle"
};
return Json(quotes);
}· FileResult – 返回一个文件,用来下载的
public ActionResult Download()
{
return File("~/Content/CompanyPlans.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "CompanyPlans.docx");
}
· EmptyResult – 一个action没有返回结果
· HttpUnauthorizedResult – 返回HTTP Unauthorized status code.
· JavaScriptResult – 返回一个JavaScript 文件.
· RedirectToRouteResult – 使用route values重定向到另外一个controller的action
最后
以上就是欣慰电源为你收集整理的asp.net mvc 页面转向及传参数的全部内容,希望文章能够帮你解决asp.net mvc 页面转向及传参数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复