mvc view the return value

MVC View various return type as follows:



Index ContentResult public () { return Content ( "test"); // browser displays the test } public EmptyResult Index () { return new new EmptyResult (); // browser displays a blank } public FileResult Index () { return File (Server .MapPath ( "~ / demo.jpg") , "application / x-jpg", "demo.jpg"); // browser Download demo.jpg } public HttpNotFoundResult Index () { return HttpNotFound (); // error messages 404 } public HttpUnauthorizedResult Index () { return new HttpUnauthorizedResult (); // unauthorized page, jump to / the Account / LogOn } public JavaScriptResult the Hello () { String JS = "Alert ( 'Are you all right?');"; return JavaScript (JS); // display the page alert ( 'you okay?');} does not perform this js, js can be executed in any view this was <script src = "@ Url.Action ( " hello ")" type = " text / JavaScript "> </ Script> } public a JsonResult Index () { var jsonObj new new = { Id =. 1, the Name =" Xiaoming ", Sex =" M ", Like =" soccer " }; return Json (jsonObj, JsonRequestBehavior.AllowGet); // return a JSON, this code may be output to the display processing JS } public RedirectResult Index () { return the Redirect ( "~ / demo.jpg"); // can jump to any path return the Redirect ( "http://www.baidu.com"); return the Redirect ( "/ List"); } public RedirectToRouteResult Index () { return RedirectToRoute (// Jump to the Action new new { Controller = " Home ", Action =" GetName " }); } public a ViewResult Index () { return View (); // this is the most common, the view returns specified // return View ( "List"); // return View ( "/ the User / List"); } public PartialViewResult Index () { return PartialView () ; // partial view, can be incorporated as a part of a further view, with substantially the same view }

Guess you like

Origin www.cnblogs.com/gougou1981/p/12193282.html