0
我正在尝试向表单中添加搜索功能。这是一个填充了类别的多选列表框,当选中该列表框时,会导致底部的表格进行相应的过滤。因此,我有两种形式,顶部是ajax搜索请求。我在其他表单中有一个hiddenfor,对于他们实际需要发布时选择的类别。问题是,当我点击搜索,这两个表单发布后,它似乎没有注册表单在另一个表单之外的事实。我无法弄清楚如何让第一个表单成为获取请求,我认为我在选项中配置了它,但显然我错过了一些东西。MVC 5如何提交表单中的ajax搜索
@using (Ajax.BeginForm(
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "vendorList"
}))
{
<div class="form-group col-sm-12">
<div class="col-md-3">
@Html.LabelFor(model => model.catIds, new { @class = "control-label col-md-2" })
</div>
<div class="col-sm-6">
@Html.ListBoxFor(model => model.catIds, new MultiSelectList(Model.Categories, "Value", "Text", Model.catIds), new { @class = "chzn-select", data_placeholder = "Select Categories..." })
@Html.ValidationMessageFor(model => model.catIds)
<input type="submit" value="Search" />
</div>
</div>
}
这是另一种形式......
@using (Html.BeginForm("Create", "item", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.HiddenFor(model => model.catIds)
@Html.AntiForgeryToken();
...attribute setting
<div class="form-group col-sm-12" id="vendorList">
<div class="post-title" style="margin-top: 0em">
<h3 style="left:auto">Invite Vendors</h3>
</div>
<div class="col-sm-9">
<table class="table table-striped">
<thead>
<tr>
<td>
<button type="button" class="btn btn-default btn-xs" id="checkall">
<span class="glyphicon glyphicon-ok"></span> Select All
</button>
</td>
<td><b>VENDOR #</b></td>
<td><b>VENDOR</b></td>
</tr>
</thead>
<tbody id="checkboxes">
@foreach (var item in Model.AllVendorUsers)
{
<tr>
<td>
<input type="checkbox" name="InvitedVendors" [email protected]>
</td>
<td>
@item.CompanyName
</td>
<td>
@item.User.PhoneNumber
</td>
</tr>
}
<tr>
<td>
<button type="submit" id="btn_Create" class="btn pull-right" value="Create">Finish</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
}
向您展示整个视图。 – 2014-11-08 05:28:13
你需要什么零件?我发布了其他表格,只有我遗漏的是属性。附录是,当我不使用Ajax时,表单按预期工作。我知道我应该把部分视图回收的部分,但现在我只需要得到这个工作,然后我会添加它。 – Rasen244 2014-11-08 20:58:48
看不到任何内容表明这两个表单会同时回传。在两种方法中设置一个断点以确保实际发生的是什么。 '@ Html.HiddenFor(model => model.catIds)'在第二种形式中是没有意义的,因为它的值将在页面第一次加载时成为初始值(除非您有一些JavaScript基于选择进行更新在第一种形式) – 2014-11-09 03:11:26