I have a form that passes through ajax to the controller. The controller collects data from the Model, and then creates a new ViewModel and passes it to a partial view, which is then updated on the Client.
The problem is that the text fields are not cleared as expected. The message comes into view as expected, so it makes no sense that the text fields are not cleared.
However, there seems to be a problem with the browser, as it is an HTML result that notes that nothing matters:
<input id="Address_Address1" name="Address.Address1" type="text" value="" />
However, the user sees the value that was previously entered.
Here is the controller:
order = new OrderViewModel();
order.Message = "Report Added to your cart";
return PartialView("_NewOrderPartial", order);
This is a partial view:
@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>
source
share