c# - Create drop down list from List ASP.NET MVC -


i have typed view model , in 1 of class object passing list of options need present in @html.dropdownlist

view model

 public class createcampaign_vm {     public marketingcampaign marketingcampaign { get; set; }      public list<marketingcampaigntype> marketingcampaigntype { get; set; } } 

controller method

 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());     } 

razor view

@model app.business.entities.createcampaign_vm   @using (html.beginform("createcampaign_title", "campaign", formmethod.post, new { id = "createcampaigntitleform" }))         {          .....           @html.dropdownlistfor(// 'marketingcampaigntype object' need here           //...        } 

try this:

@html.dropdownlistfor(m => m.marketingcampaign , new selectlist(model.marketingcampaigntype, "campaigntypetitle", "campaigntypeid"), new { id = "yourelementidifany", @class = "yourclassnameifany" }) 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -