I believe that when you do WebForm, you often encounter the background CS file in the page to modify the page display style, display (hidden), or pop-up box according to the data running results. At that time we will use the Scriptmanage or page to register a section of JS to achieve page loading shows the effect we need.
In MVC, the Scriptmanage, Page object allows us to easily register the script with the page, which can only be done by Ajax.
Prerequisite:
1. First you need to refer to the jquery package and Unobtrusive-ajax in the loaded page
<script type= "Text/javascript" src= "@Url. Content (" ~/scripts/jquery-1.5.1.min.js ")" > </script> <script type= "Text/javascript" src= "@Url. Content (" ~/scripts/jquery.unobtrusive-ajax.js ")" > </script >
2. Action return data in controller
The action returned by the contenttype needs to be application/x-javascript,text/javascript, because the browser can parse the application/x-javascript finally resolves to text/javascript.
The first method: Use the Content method to return Contentresult, create the contents result object by using a string and a content type, so be explicit when using the contenttype type
Using JavaScript to return Javascriptresult objects
ASP. NET MVC uses AJAX to register action JavaScript to the page and execute