【发布时间】:2011-04-04 08:55:02
【问题描述】:
我很确定我的问题很复杂。对不起,我不知道如何表达自己。接下来是情况:
public ActionResult Edit(int id)
{
CreateTrainingModel editTrainingModel = new CreateTrainingModel();
editTrainingModel.Training = training.GetByID(id);
editTrainingModel.Player = player.GetAll();
return View(editTrainingModel);
}
和 Html.EditorFor() 的编辑器模板:
@inherits System.Web.Mvc.WebViewPage<TrainingStatistics.Models.ViewModels.CreateTrainingModel>
@Html.ValidationSummary()
<table>
@Html.HiddenFor(x => x.Training.TrainingID)
<tr>
<td>Training Date</td>
<td><input type="text" id="datepicker" name="Training.Date"></td>
<td>@Html.ValidationMessageFor(x => x.Training.Date)</td>
</tr>
</table>
问题是当我想编辑它时,模型中的数据不会传递到视图。我认为这个问题是因为使用 ViewModels 而我在这里做错了..当我尝试更新仅由一个实体(例如 Player)组成的东西并且当我不使用 ViewModel 时一切都很好。
提前谢谢你!
【问题讨论】:
-
Hrm,这看起来很紧凑而且很实用……
-
问题是因为我没有在 datepicker 控件的输入类型中指定值...使用 @Html.TextBoxFor(x => x.Training.Date, new { id = "datepicker" })解决了问题.. 或者只是 value="@Model.Training.Date" ...欢呼
标签: asp.net-mvc viewmodel editing