I'm trying to remove items from a list that I created following This question. The add part of the functionality works just fine.
When I specify an event in the onclick event on the partial page I get a javascript error. "'Function Name' is undefined." Looking it over I think the onclick attribute isn't required if the jquery is working. However, even after updating it to work with the latest version of JQuery it isn't detecting a click event, or at least it isn't triggered.
Main_View just the relevant sections
<table id="pastSchoolContainer">
<tr>
<td>
<input type="button" id="addPastSchool" name="addPastSchool" value="Add School" />
</td>
</tr>
@foreach (var school in Model.SchoolsAttended)
{
Html.RenderPartial("_SchoolRemovablePartial", school, new ViewDataDictionary(ViewData)
{
TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "SchoolsAttended" }
});
}
</table>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$(document).ready(function () {
$("#addPastSchool").click(function () {
$.ajax({
async: false,
url: '/Student/AddPastSchool',
}).success(function (partialView) {
$("#pastSchoolContainer").append(partialView);
return;
});
});
return;
});
$("#addPastSchool").on("click", ".deleteRow", function () {
$(this).parents("#pastSchool:first").remove();
return false;
});
</script>
}
_SchoolRemovablePartial
@model ScholarSponsor.Models.SchoolModel
@using ScholarSponsor.Helper
@using (Html.BeginCollectionItem("pastSchool"))
{
<tr id="pastSchool">
<td>
@Html.EditorForModel()
<br />
@*<a href="#" id="deleteRow" class="deleteRow" onclick="deleteFunction()">Delete</a>*@
<input type="button" class="deleteRow" value="Remove School" onclick="remove()" />
</td>
</tr>
}