I have javascript function which appends PartialView into div. Everything works fine, except that PartialView contains some <script></script> scripts. And those dynamically appended functions are not found by jQuery - Uncaught ReferenceError: getIDc4 is not defined.
My JS function
var url = '@UrlHelper.GetFullUrl("Inventories/GetFilterRow")'; //this returns partial view
$.ajax({
type: 'POST',
data: { aRef: aRef },
url: url,
success: function(data) {
$('.filter').append($(data)[0]);
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
}
});
and partial view
...
@{
int id = Model != null ? Model.Id : 1;
}
<div id="@Html.Raw("FilterCondition" + id)">
...
...
...
@{
string getIdcFunction = string.Format("getIDc{0}", id);
}
<script>
@{
@:function
@getIdcFunction<text>() {
var grid = $("@Html.Raw("#field"+id)").data("kendoDropDownList");
var item = grid.value();
return { IDc: item };
}
</text>
}
</script>
</div>
How can I get those dynamically appended functions get working?
When I generate the partial view by using on page loading with
@Html.Partial("GetFilterRow", new {Id = 1})
everything works fine. The only problem is when this view is appendend via jquery and ajax. Then those functions are not found.
Thanks for help.