【问题标题】:MVC 3 DropDownListFor ModelState.IsValid is FalseMVC 3 DropDownListFor ModelState.IsValid 为 False
【发布时间】:2011-07-28 21:25:58
【问题描述】:

在查看.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 而不是对象。

【问题讨论】:

    标签: guid html.dropdownlistfor


    【解决方案1】:

    通过将此行放入代码并在其上设置断点,您可以在 Watch 窗口中获得验证错误列表:

    var x = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-16
      • 2011-02-22
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多