我有一个强类型的视图模型,在一个类对象中,我传递了我需要在@html.Dropdownlist中显示的选项列表
public class CreateCampaign_VM
{
public MarketingCampaign MarketingCampaign { get; set; }
public List<MarketingCampaignType> MarketingCampaignType { get; set; }
}
private CreateCampaign_VM GetCampaignObject()
{
CreateCampaign_VM _CampaignObject = new CreateCampaign_VM();
_CampaignObject.MarketingCampaignType.Add(new MarketingCampaignType {
CampaignTypeID = 1,
CampaignTypeTitle = "Email",
Description = "Email"
});
_CampaignObject.MarketingCampaignType.Add(new MarketingCampaignType
{
CampaignTypeID = 2,
CampaignTypeTitle = "Text",
Description = "Text"
});
_CampaignObject.MarketingCampaignType.Add(new MarketingCampaignType
{
CampaignTypeID = 3,
CampaignTypeTitle = "Post",
Description = "Post"
});
return _CampaignObject;
}
...
public ActionResult CreateCampaign_Title()
{
return PartialView("CreateCampaign_Title_Partial", GetCampaignObject());
}
@model App.Business.Entities.CreateCampaign_VM
@using (Html.BeginForm("CreateCampaign_Title", "Campaign", FormMethod.Post, new { id = "CreateCampaignTitleForm" }))
{
.....
@Html.DropDownListFor(// 'MarketingCampaignType object' need help here
//...
}
答案 0 :(得分:0)
试试这个:
@Html.DropDownListFor(m => m.MarketingCampaign , new SelectList(Model.MarketingCampaignType, "CampaignTypeTitle", "CampaignTypeId"), new { id = "yourElementIdIfAny", @class = "yourClassNameIfAny" })