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