可以取到ViewBag的值 注意:两次地址栏都是输入的Test/f1
return View();//返回要领名对应的视图
return View("aaa");//返回名称为aaa的视图
2.返回文本内容
return Content("hello world");
3.返回重定向
return Redirect("https://www.baidu.com");
return Redirect("~/Test/1.html");
return RedirectToAction("同一个controller类下的要领名");
return RedirectToAction("action name","controller name"); //重定向到指定的controller类下的指定的action要领
4.返回文件
return File(byte[] fileContents, string contentType);
return File(Stream fileStream, string contentType);
return File(string fileName, string contentType);
5.返回json
Person p1 = new Person(){Id=1,Name="zhangsan"};
return Json(p1);
Redirect 和 View 的区别
Redirect和处事器进行了两次交互,第一次是F1,第二次是Index,所以第2次已经取不到ViewBag的值了
View是让处事器把指定的cshtml的内容运行衬着后给到浏览器,只有一次交互,可以取到ViewBag的值
注意:两次地点栏都是输入的Test/f1,Redirect重定向到index,而View是把index的内容衬着出来后放在f1页面显示。
ASP.NET MVC中ActionResult的差别返回方法
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32668.html