drop down menu - Populate DropDownListFor and default value is guid parameter -


i have populated dropdownlistfor correct values. i'm passing guid parameter, don't know how set default value guid.

view

<div class="form-group">   @html.labelfor(model => model.parent)   @html.dropdownlistfor(model => model.parent, new selectlist(model.allparents, "id", "name"), string.empty, new { @class = "form-control" })   @html.validationmessagefor(model => model.parent) </div> 

viewmodel

public class parentviewmodel {      public list<parent> allparents { get; set; }       [displayname("parent")]      public guid? parentid { get; set; }  } 

controller

[httpget] public actionresult create(guid? id) {              var parentviewmodel = new parentviewmodel             {                 allparents = _service.getall().tolist()             };             return view(parentviewmodel);         }     } 

you need replace string.empty "default value want"

@html.dropdownlistfor(model => model.parent, new selectlist(model.allparents, "id", "name"), "default value here here", new { @class = "form-control" }) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -