2009-08-31 44 views
0

我有一个发布multiselect的问题,我得到的错误: “有没有ViewData项与关键'NotificationUsergroups'类型'IEnumerable'”。有没有ViewData项目的关键

在控制器中,我有:

  MultiSelectList NotificationUsergroups = new MultiSelectList(Usergroups, "UsergroupID", "UsergroupName", selectedNotificationUsergroupIDs); 

     ViewData["NotificationUsergroups"] = NotificationUsergroups; 

在视图中我有:

<%= Html.ListBox("NotificationUsergroups")%> 

与后行动:

[AcceptVerbs(HttpVerbs.Post)] 
    public ActionResult ObjectEdit([BindAttribute(Include = "BookingObjectID,BookingObjectName,Activated,ActivationStartDate,ActivationEndDate,AvalibleObjects,AvalibleObjectsPerBooking")]BookingObject bookingobject, int[] Objectcategories, int[] NotificationUsergroups, int[] CancellationUsergroups) 
    { 
     if (ModelState.IsValid) 
     { 
      try 
      { 
       _bs.SaveBookingObject(bookingobject); 

       if (NotificationUsergroups != null) 
        _bs.SaveNotificationUsergroups(bookingobject.BookingObjectID, NotificationUsergroups); 

       return View("CreateObject", new BookingObjectsAdminEditViewModel { BookingObject = bookingobject }); 
      } 
      catch { 
       ModelState.AddModelError("SomeError", "errrrrrrrrror"); 
      } 
     } 

可能是什么问题?我检查了拼写和所有,如果我不运行multiselect列表的作品。

什么使数据“消失”?

在此先感谢 /M

+0

你是什么意思“在我有控制器”? – 2009-08-31 10:00:32

回答

1

您需要设置可视数据的POST方法接受,以及因为如果有一个错误,将返回到原来的看法。

善良,

或者将它们包含在模型:)你需要改变看法寿。

+0

如果我在模型中使用它,应该是什么类型? – 2009-08-31 11:42:17

+0

这将是一个多选列表还, 在您看来它会是这样的: <%= Html.ListBox(“NotificationUsergroups”,Model.NotificationUsergroups)%> – 2009-08-31 11:52:41

+0

我应该使用什么类型的,获得式missmatch错误 – 2009-08-31 13:03:54

0

您的操作必须设置您的ViewData。

如果你的行动电话

ViewData["NotificationUsergroups"] = NotificationUsergroups; 

一切都应该是正常的。

相关问题