Good day.

I need from PartialView to call the Ajax script to load data

<script type="text/javascript"> function changed(data) { $.Ajax({ type: "GET", url: '@Url.Action("GetDepsAsync", "Employees")', data: { id: data }, success: function(result){ operate(data); } }) } </script> 

But, the section of scripts @section scripts {} does not work in PartialView

Is there a way to execute an Ajax request from PartialView?

  • In addition, I have a mistake $.Ajax({ . It is necessary to change it to $.ajax({ . Several times this rake occurred. - bodynar

1 answer 1

The framework design is such that sections do not work in partial views. Asp.Net MVC forces Views to be responsible for including the necessary scripts. So Partial Views should not be responsible for this.

You can place a section with the necessary scripts in the main view.

You can also create your HtmlHelper to add similar functionality for partial views. Look this question