ArticleDirectory
- 1. accx page
- Ii. return text
- 3. Return JSON
- 4. Output JS files
- V. page Jump
- 6. Display files
In the previous article, all the actions we see are return view (); we can think of this return value to parse An ASPX file. Its return type is actionresult, which is simpleCodeIs:
Public actionresult index () <br/>{< br/> return view (); <br/>}
So what else can we return besides return view? How to return? This is the problem to be solved in this chapter.
1. accx page
Scenario: return code snippets. For example, Ajax returns a subpage,
1. Create an action as follows:
Public actionresult ascx () <br/>{< br/> return partialview (); <br/>}
2. Create another view, right-click the action, and select addview.
Note: select
3. A new ascx page is created, so we can rewrite it as follows:
<Div> <br/> get a div <br/> </div>
The following page is displayed after running:
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:
Public actionresult text () {<br/> return content ("this is a piece of text"); <br/>}
3. Return JSON
Sometimes, when Ajax is called, the returned object is required to be serialized in JSON format, for example:
Public actionresult showjson () <br/>{< br/> var M = new rocketindexmodel <br/>{< br/> name = "Xue jingming ", <br/> sex = true <br/>}; <br/> return JSON (m); <br/>}
Response text:
{"Name": "Xue jingming", "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 these files as follows:
Public actionresult JS () <br/>{< br/> return JavaScript ("Var x = 0;"); <br/>}
We can access it to get a normal page, but its content-type: Application/X-JavaScript; charset = UTF-8
5. page Jump 5.1 jump to URL
<textarea cols="82" rows="8" name="code" class="c-sharp">Public actionresult rdurl () <br/>{< br/> return redirect ("http://blog.csdn.net/rocket5725"); <br/>}</textarea> 5.2 jump to action
Public actionresult rdaction () <br/>{< br/> return redirecttoaction ("Index", "Rocket"); <br/>}
5.3 jump to the routing rule
Public actionresult rdrouting () <br/>{< br/> return redirecttoroute ("default ", // route name <br/> New {<br/> controller = "Rocket", <br/> action = "Index" <br/> }); <br/>}
6. Display files
Public actionresult FN () <br/>{< br/> return file (<br/> "/content/site.css" // file path <br/>, "text/CSS" // file type <br/>); <br/>}