EDIT - I am putting in more info to help get the answer. What I am doing is using autocomplete to add items to a list;
<section id="rightSide" class="shrinkwrap" style="float: right;margin-top:10px;width:500px;">
<fieldset>
<legend>Select Other Materials</legend>
<form method="get" action="@Url.Action("CreateOtherMaterials", "DataService")"
data-scd-ajax="true" data-scd-target="#otherMaterialList">
<p>Select a Material: <input type="search" name="searchOtherMaterial" id="searchOtherMaterial" data-scd-autocomplete="@Url.Action("AutocompleteOtherMaterial", "DataService")" style = "width: 300px;" class="submitOtherMaterialSelectionNew" data-scd-add-other-material="@Url.Action("AddOtherMaterialNew", "DataService")"/>
@Html.DialogFormButton("Add New Material", Url.Action("AddMaterial", "Popup"), "Add New Material", null, Url.Action("Create"))
</p>
</form>
@Html.Partial("_OtherMaterials", Model.SupplierMaterialList.Where(x => x.PrimaryMaterialFlag == false).ToList())
</fieldset>
</section>
So everytime an item is entered, the list grows. I am wondering if the problem is that the script does not pick up the latest updates to the page? The partial view _OtherMaterials looks like
@model IList<SupplierMaterial>
<div id="otherMaterialList" >
<p>These materials have now been added for this supplier</p>
<table>
@Html.DisplayForModel()
</table>
</div>
This is a grid that uses the DisplayTemplate below to display rows of data;
@model SupplierMaterial
<tr>
<td>@Model.Material.MaterialName </td>
<td>
<form class="shrinkwrap" method="get" action="@Url.Action("RemoveOtherMaterial", "DataService")">
<input type="button" value="Remove" class="removeItem"/>
@Html.HiddenFor(model => model.MaterialId)
</form>
</td>
</tr>
The form does not overlap with any other. When the user clicks on the button this code is meant to run;
$('.removeItem').click(function () {
alert("test");
var $form = $(this).closest("form");
var options = {
url: $form.attr("action"),
type: $form.attr("method"),
data: $form.serialize()
};
$.ajax(options).done(function (data) {
var $tr = $(this).closest("tr");
$tr.remove();
});
return false;
});
However the click event is not captured by this code, and I can't work out why