How to register javascript in ASP.NET MVC action?

For example, I want to show the jQuery dialog after inserting or editing an entry in Action, in webform I can use the following method of registering a js script on a page:

page.RegisterStartupScript(key, "<script language='javascript' defer>" + script + "</script>");

but this does not work in MVC, so how can I do this?

thank!

+3
source share
1 answer

In ASP.NET scripts, MVCs are not logged in controller actions. There is a separation between controllers and views. Therefore, you can directly put scriptin the appropriate view:

<script type="text/javascript" src="somescript.js"></script>

script. , AJAX script , script DOM:

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'somescript.js';
$('#someElement').append(script);
+3

Source: https://habr.com/ru/post/1752956/


All Articles