I have an EditorFor template that looks like this,
@{
Layout = null;
@Html.EditorFor(model => model.Name)
@Html.EditorFor(model => model.Value)
}
for a List of Key/Value pairs. Here is the Model.
public List<NameValuePair> Parameters { get; set; }
This produces a list of editable boxes. I need to delete a particular element (so when the page refreshes the whole "row" is gone). I am having trouble finding the index of that element to pass to the delete function in my controller. Is there an easy way to find a particular index in a EditorFor template?
Update--
This is what the code in the view looks like. Which displays the list of parameters.
@Html.LabelFor(model => model.Parameters)
@Html.EditorFor(model => model.Parameters)
<input type="submit" name="command" value="addParam" class="btn btn-default btn-primary" />
And this is what the delete method I am attempting to use in the controller looks like.
public ActionResult DeleteParamaters(long id, int index)
{
var templateStep = Biz.GetTemplateStep(id);
templateStep.Parameters.RemoveAt(index);
return View("CreateTemplateStep", templateStep);
}
My end goal is a delete button next to each list item, and when clicked will delete that particular item from the list.