我的MVC表單將不會提交,除非我在我的TextBoxFor字段中有一個值。我正在使用TextBoxFor,因爲我確實需要存儲在模型屬性中的字段的值。我需要以下兩種解決方案之一,或者滿足我的需求。我需要提交表單以便能夠將常規文本框的值保存到模型屬性,或者當我的TextBoxFor爲空時允許提交。提交MVC空剃刀TextBoxFor字段
目前我的代碼看起來是這樣的:
@using (Ajax.BeginForm("PartialResults", "Students", new { LoadItemsOnly = true }, new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "find-results" }))
{
<div class="inline-ct">
<table>
<tr>
<td><span class="lbl">Name: </span></td>
@Html.TextBoxFor(m => m.Filter, new { autofocus = "autofocus", id = "name" })
</tr>
<tr>
<td><span class="lbl">@Html.DisplayNameFor(m => m.LocationID): </span></td>
<td>@Html.DropDownListFor(m => m.LocationID, new SelectList(Model.Locations, "Key", "Value"))</td>
</tr>
<tr>
<td><span class="lbl">@Html.DisplayNameFor(m => m.ADGuid): </span></td>
<td>@Html.DropDownListFor(m => m.ADGuid, new SelectList(Model.Teachers, "Key", "Value"))</td>
</tr>
<tr>
<td><span class="lbl">@Html.DisplayNameFor(m => m.ClassCode): </span></td>
<td>@Html.DropDownListFor(m => m.ClassCode, new SelectList(Model.SchoolClasses, "Key", "Value"))</td>
</tr>
<tr>
<td><button type="submit" class="btn-primary" id="btn-find">Find</button></td>
<td></td>
</tr>
</table>
</div>
<div id="student-find-results" class="row">
</div>
}
如前所述時,有一個值TextBoxFor這工作得很好,但形式是不是如果是空的提交。任何幫助將不勝感激。
注意: 我試圖添加一個onclick甚至到按鈕,但它不提交給控制器。
請看看你的模型,看看[必填]數據註釋。爲什麼你改變過濾器 – Amila 2014-12-03 16:07:55
的'id'哇......我的臉有點紅。修復它,謝謝。如果你把這個作爲答案,我會標記爲這樣。感謝您的幫助! – mgrenier 2014-12-03 16:10:56