In my partial view I have this ajax actionlink
@foreach (var times in Model.ProvidedDateTimes)
{
<tr>
<td>
@times.StartDateTime to @times.EndDateTime
</td>
<td> @Ajax.ActionLink("Delete", "DeleteResponse", new { responseid = @times.ResponseId }, new AjaxOptions { UpdateTargetId="dummy",OnBegin = "begin",OnComplete="complete",OnFailure="fail",OnSuccess = "success"})</td>
</tr>
}
These are the functions
$(function begin() {
alert("begin");
});
$(function complete() {
alert("complete");
});
$(function fail() {
alert("fail");
});
function deleteResponse(id){
var url = $("#providedTimes").data('url');
url = url + "&t=" + new Date().getTime();
$.get(url, function (data) {
$('#providedTimes').html(data);
});
};
When I run the application I get javascript alert begin complete then fail, all twice.
When i try to click the delete i get error on console that says
The bundles I render are
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-2.1.0.min.js",
"~/Scripts/jquery.unobtrusive-ajax.min.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.min.js"));
and in _layout view
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/Scripts/jquery-ui-1.10.4.js")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/Kendo")
@Scripts.Render("~/bundles/toastr")
Any idea why I'm getting error in console?
$()? Perhaps if your page just saidfunction begin()instead of$(function begin(){})document.readyevent. they are not available outside of it. Create a<script>tag before your form (orforeach...) and define the functions there.