For example, I want to show a jQuery dialog after insert or edit a record in Action, in webform I can use the follow way to register js script to the page:
page.RegisterStartupScript(key, "<script language='javascript' defer>" + script + "</script>");
but this doesn’t work in MVC, so how can I do this?
thanks!
In ASP.NET MVC scripts are not registered in controller actions. There’s a separation between controllers and views. So you could directly put the
scriptin the corresponding view:When the view is rendered it will load the script. Now if you are doing AJAX and you want to add a script inside the success callback you could create the
scriptelement and append it to the DOM: