我有一個通過ajax提交給控制器的表單。 Controller從模型中收集數據,然後創建一個新的ViewModel並將其傳遞給部分視圖,然後在客戶端上更新該部分視圖。爲什麼清除後文本框不能清除模型
問題是,文本框未按預期清除。該消息按預期到達視圖中,因此TextBoxes未被清除是沒有意義的。
然而,這似乎是一個瀏覽器的問題,因爲這是生成的HTML,有哪些注意事項,並沒有在任何有價值的東西:
<input id="Address_Address1" name="Address.Address1" type="text" value="" />
然而,用戶可以看到這是priorly輸入的值。
這裏是控制器:
//Process Order Here
//This should clear out the ViewModel.
order = new OrderViewModel();
order.Message = "Report Added to your cart";
return PartialView("_NewOrderPartial", order);
這是局部視圖:
@model NTC.PropertySearch.Models.OrderViewModel
@using (Ajax.BeginForm("NewOrder", "Order", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "neworder" }))
{
<div id="neworder">
<table>
<tr>
<th style="width: 300px;">
<h3>Enter property address below</h3>
</th>
<th style="width: 30px;"></th>
<th style="width: 300px;">
<h3>Choose your report below</h3>
</th>
</tr>
<tr>
<td>
<div class="form">
<table>
<tr>
<td>
@Html.LabelFor(m => m.Address.Address1)
</td>
<td>
@Html.TextBoxFor(m => m.Address.Address1)
</td>
<td>
@Html.ValidationMessageFor(m => m.Address.Address1)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.Address.Address2)
</td>
<td>
@Html.TextBoxFor(m => m.Address.Address2)
</td>
<td>
@Html.ValidationMessageFor(m => m.Address.Address2)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.Address.City)
</td>
<td>
@Html.TextBoxFor(m => m.Address.City)
</td>
<td>
@Html.ValidationMessageFor(m => m.Address.City)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.Address.State)
</td>
<td>
@Html.TextBoxFor(m => m.Address.State)
</td>
<td>
@Html.ValidationMessageFor(m => m.Address.State)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.Address.ZipCode)
</td>
<td>
@Html.TextBoxFor(m => m.Address.ZipCode)
</td>
<td>
@Html.ValidationMessageFor(m => m.Address.ZipCode)
</td>
</tr>
</table>
<input type="submit" value="Add Report" />
@Html.DisplayFor(m=> m.Message)
</div>
</td>
</tr>
</table>
</div>
哪個瀏覽器?如果它是IE,它可能是通過保留內容來「幫助」你。 – Maess