The actions we see above are all return view (); we can think of this return value to parse An ASPX file. And its return type is actionresult, such
PublicActionresult index (){ReturnView ();}
In addition to view (), what values can we return here?
I. ascx page
Scenario: ReturnCodeFor example, Ajax returns a subpage.
Create an action first.
PublicActionresult ascx (){ReturnPartialview ();}
Next we will create another view, which is still right-clicked in the action and addview.
Note that this option is selected in the figure.
So we created an ascx page, so we can rewrite it less.
<% @ Control Language = "C #" inherits = "system. Web. MVC. viewusercontrol" %><Div>Get a div</Div>
Run to get the page
Ii. return text
In addition to the above situations, sometimes we will only return a piece of text.
In this case, we can use the following action form:
PublicActionresult text (){ReturnContent ("This is a piece of text.");}
3. Return JSON
Sometimes, when Ajax is called, the returned object is required to be serialized in JSON format, for example:
PublicActionresult showjson () {var M =NewEiceindexmodel {name ="ZOU Jian", Sex =True};ReturnJSON (m );}
Response text:
{"Name":"ZOU Jian","Sex":True}
4. Output JS files
Most JS files are static files, but sometimes JS files may need to be dynamically generated. In this case, we can output
PublicActionresult JS (){ReturnJavaScript ("VaR x = 0;");}
We can access it to get a normal page, but its content-type: Application/X-JavaScript; charset = UTF-8
V. page Jump
1. Jump to URL
PublicActionresult rdurl (){ReturnRedirect ("Http://www.baidu.com");}
2. Jump to action
PublicActionresult rdaction (){ReturnRedirecttoaction ("Index","Eice");}
3. Jump to the routing rule
PublicActionresult rdrouting (){ReturnRedirecttoroute ("Default",// Route nameNew{Controller ="Eice", Action ="Index"});}
6. Display files
PublicActionresult FN (){ReturnFile ("/Content/site.css"// File path ,"Text/CSS"// File type );}
Let's talk about filter in the next section.