从@Html获取值/SelectedValue.循环上的的编辑器



在下面的代码片段中,我想获得"Html。编辑器;使用Jquery。我已经尝试了很多方法。但我做不到。感谢您的意见。

<table class="table table-striped" id="tblEvents">
<thead>
<tr>
<th class="col-md-6 Subheading-2">Event Name</th>
<th class="col-md-6 Subheading-2">Event Date</th>
</tr>
</thead>
<tbody>
@for(int i=0;i<Model.ModelEvents.Count;i++)
{
<tr>
<td class="col-md-6">
@Html.HiddenFor(model=>model.ModelEvents[i].NAME)
@Html.HiddenFor(model=>model.ModelEvents[i].ADDRESS)
@Html.HiddenFor(model=>model.ModelEvents[i].PINCODE)
@Html.DropDownListFor(model=>model.ModelEvents[i].EVENTNAME,new SelectList(Model.Events,"Value","Text",Model.ModelEvents[i].EVENTNAME),new { @class = "form-control eventname", style = "max-width:300px" })


</td>
<td class="col-md-6">
@Html.EditorFor(model => model.ModelEvents[i].EVENTDATE, new { @class = "text  form-control eventdate" })
</td>
</tr>
}
</tbody>
</table>

编辑


给控件一个id,并且由于它在循环中;i〃;以确保唯一的ID

new { @class = "text form-control eventdate", id = "foo_" + i }

然后您可以使用这个id作为jquery查找的参考

这将匹配ID以"0"开头的任何输入;foo_;因此将匹配";foo_0"foo_ 1"foo_ 2";ect

$('input[id^="foo_"]').).each(function() {
console.log($(this).val())
});

我希望这能帮助

最新更新