The action you see is a return View (); we can treat this as a return value for parsing an ASPX file. And its return type is actionresult as
Public ActionResult Index ()
{
return View ();
}
Besides view () what value can we use here to return?
I. ASCX page
Scenario: To return a snippet, such as Ajax, to return a sub-page
Let's start with a new action
Public ActionResult Ascx ()
{
return Partialview ();
}
We'll build a view below, still in action, right-click, AddView.
Note the picture is checked.
So I created an ascx page, and we're going to rewrite it a little bit.
<%@ Control language= "C #" inherits= "System.Web.Mvc.ViewUserControl"%> <div> get a div </div>
Run, get the page
Second, return text
In addition to the above, we sometimes return only a piece of text.
At this point we can use the following action form:
Public ActionResult Text ()
{
Return Content ("This is a piece of text");
}
Third, return JSON
Sometimes when we call Ajax we also ask that the returned object be the result of JSON serialization, such as:
Public ActionResult Showjson ()
{
var m = new Eiceindexmodel{name = "Kingjian", Sex = true};
Return Json (m);
}
Return text:
{"Name": "Kingjian", "Sex": true}
Iv. Output JS file
Most of the time JS files are static, but sometimes JS files may also be generated dynamically at this point we can output
Public ActionResult Js ()
{
return JavaScript ("var x=0;");
}
We visit, get a normal page but its content-type:application/x-javascript; Charset=utf-8
Five, page jump
1. Jump to URL
Public ActionResult Rdurl ()
{
Return Redirect ("http://www.baidu.com");
}
2. Jump to Action
Public ActionResult rdaction ()
{
Return redirecttoaction ("Index", "Eice");
}
3. Jump to Routing Rule
Public ActionResult rdrouting ()
{
Return Redirecttoroute ("Default",//route name
New{controller = "Eice", Action = "Index"});
}
Vi. Display Files
Public actionresult FN ()
{
Return file ("/content/site.css"//File path
, "TEXT/CSS"//File type
);
}
MVC Controller return format