0

净MVC。我已经为 viewbag 属性分配了一个对象列表,谁能告诉我如何在视图中获取列表以在下拉列表中使用它?这是我的控制器代码和查看代码

控制器:

  public ActionResult GetSection(int sectionId,int contactId)
        {
            ContactDetailSectionModel contactDetailSection = new ContactDetailSectionModel { SectionId = sectionId,ContactId=contactId };
            contactDetailSection.FetchAllSubsections();

            ContactDetailSectionModel customSections = new ContactDetailSectionModel();
            customSections.FetchCustomSubSections();

            if(customSections != null && customSections.ContactDetailSubSections != null)
            {
                ViewBag.CustomSubSections = customSections.ContactDetailSubSections;
            }

            return PartialView("~/Views/Contacts/Details/EditSection.cshtml", contactDetailSection);
        }

查看代码:

@Html.DropDownListFor(m => m.ContactDetailSubSections[1], new SelectList(ViewBag.CustomSubSections , "Name", "Name",Model.ContactDetailSubSections[1].Name)) 
 @Html.TextAreaFor(m => m.ContactDetailSubSections[1].Text)   
4

1 回答 1

0

我认为你的第一个参数@Html.DropDownlist应该是字符串或一些标量,它不能是一个集合。

于 2013-02-19T07:34:36.323 回答