view .cshtml页面:
@{var items = new SelectList(Model.Rooms, "RoomGUID", "FullName");}
@Html.DropDownListFor(x => x.Request.Room, @items)
在ViewModel .cs页面中:
public class NewRequestView
{
public IEnumerable<Room> Rooms { get; set; }
public Request Request { get; set; }
}
在控制器中。cs页面:
NewRequestView nrv = new NewRequestView();
nrv.Request = r;
nrv.Rooms = db.Rooms;
return View(nrv);
数据在ModelState.Value中。AttemptedValue,而不是ModelState。ISValid为false。任何想法?因为它返回的是GUID而不是对象。
通过将这行放在代码中并在其上设置断点,您可以在Watch窗口中获得验证错误列表:
var x = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);