My Main View:
@Ajax.ActionLink("append smth", "AddSmth", new AjaxOptions { UpdateTargetId = "smthContainer", InsertionMode.InsertAfter })
<div id="smthContainer"></div>
My Controller:
public ActionResult AddSmth()
{
return PartialView("Smth");
}
Smth partial view:
<input type="text" id="dateOfSmth" />
<script type="text/javascript">
$(document).ready(function () {
$('#dateOfSmth').datepicker();
});
</script>
The problem is that ready function is called before partial view is added to document, so $('#dateOfSmth') is empty. Everything works fine if I replace InsertionMode.InsertAfter with InsertionMode.Replace. Do you have any idea why is not it woking correctly with InsertionMode.InsertAfter?
EDIT: works well when appending view with jQuery:
<a href="javascript:addSmth();"> Add Smth </a>
<script type="text/javascript">
function addSmth() {
$.get('@Html.Raw(Url.Action("AddSmth"))', null, function (view) {
$('#smthContainer').append(view);
});
}
</script>