【发布时间】:2019-05-21 01:33:45
【问题描述】:
我正在尝试将视图模型传递给我的控制器。
@if (User.IsInRole("Customer"))
{
<input type="button" class="btn btn-danger" value="Rent Car" onclick="location.href='@Url.Action("PassingCar", "Bookings", new { id = item.VehicleID, Model = Model.Booking })'" />
}
我正在使用动态模型,因此我可以在此视图中同时使用 Vehicle 和 Booking。
当代码到达我的控制器时,ID 已被传递,但 ViewModel 中的数据消失了。
public ActionResult PassingCar( int id, CreateBookingViewModel createdModel)
{
///Checks that Vehicle exists in DB and v property is not null
if (v == null)
{
return HttpNotFound();
}
else
{
/// sets the Vehicle attribute of the BookingViewModel to vehicle passed over
createdModel.Vehicle = v;
}
return RedirectToAction("Create", "Bookings");
}
如果有人知道我做错了什么,将不胜感激。
【问题讨论】:
标签: c# asp.net model-view-controller asp.net-mvc-5 viewmodel