我无法访问隐藏字段PartsId。来自此的输出HTML给出了字段part_PartsId。我如何从typeAhead函数中获取它的值?我的JavaScript正在触发,但似乎只返回触发它的typeahead对象信息。
<div class="input-group col-lg-3 scrollable-dropdown-menu">
<div class="input-group-addon">@Html.LabelFor(a => part.Part)</div>
@Html.HiddenFor(a => part.PartsId)
@Html.EditorFor(a => part.Part, new { htmlAttributes = new { @class = "form-control typeahead" } })
</div>
我的JavaScript文件
$(".typeahead").on("typeahead:selected", typeAhead)
.on("typeahead:autocompleted", typeAhead);
function typeAhead(obj, suggestion) {
var test = $(this).parent().find('partidClass').first();
}
更新:显示MVC生成的HTML
似乎相关 <div class="input-group">
<div class="input-group-addon"><label>Part</label></div>
<input class="partidClass"type="hidden" value="12345" />
<input class="form-control typeahead text-box single-line" type="text" />
</div>