Я знаю, что этот вопрос задан примерно 100 раз, я прошел через них, я не вижу ничего, что я мог бы сделать неправильно. Любая помощь была бы оцененаMVC BeginForm сообщение не обязательное для списка
При отправке обратно список ImportModel пуст.
@model Models.ImportModel
<div class="main-content">
<div class="container">
<h1>Uploaded Cars</h1>
@using (Html.BeginForm("Confirm", "Import", FormMethod.Post, new { @class = "form-horizontal" }))
{
<table id="importVehiclesTable" class="table">
<thead>
<tr>
<th>Registration</th>
<th>Details</th>
<th></th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.Vehicles.Count; i++)
{
<tr>
<td>@Html.DisplayFor(m => m.Vehicles[i].RegistrationNumber)</td>
<td>@Html.DisplayFor(m => m.Vehicles[i].Name)</td>
<td></td>
</tr>
}
</tbody>
</table>
<br />
<br />
<input type="submit" value="Import Vehicles" class="btn btn-primary" />
<input type="reset" value="Back" class="btn" onclick="history.back();" />
}
</div>
Моя модель,
/// <summary>
///
/// </summary>
public class ImportModel : BaseModel
{
/// <summary>
/// Gets or sets the cars.
/// </summary>
/// <value>
/// The cars.
/// </value>
public List<VehicleAddViewModel> Vehicles { get; set; }
}
мое действие, но автомобиль OBJ является нулевым.
[HttpPost]
public ActionResult Confirm(ImportModel importModel)
{
//Will be saving to the DB here
return null;
}
Можете ли вы показать свое действие 'Get'? – ediblecode
Вы используете DisplayFor() MVC не опубликует Назад. попробуйте поместить их в HiddenFor или TextBoxFor() Связанные: http://stackoverflow.com/questions/12314849/html-displayfor-not-posting-values-to-controller-in-asp-net-mvc-3 –
Также см. ответ здесь: http://stackoverflow.com/questions/18448247/displayfor-is-not-keeping-data-in-viewmodel-on-postback –