.net - Bind model to DropDownList using Razor syntax -



.net - Bind model to DropDownList using Razor syntax -

okay, have view next razor syntax:

@model doggropi.models.wellsearch <div class="container-fluid"> <h2>well search</h2> @for (int = 0; < model.counties.count; i++) { @html.displayfor(m => m.counties[i].countyname) } </div>

it displays:

value 1value 2value 3

that want can't bind @html.dropdownlistfor. proper syntax so?

my model this:

public partial class countyinfo { public string countyname { get; set; } }

models:

public class wellsearch { public int countyid { get; set; } public ienumerable<countyinfo> counties { get; set; } } public partial class countyinfo { public int countyid {get; set;} public string countyname { get; set; } }

view:

@html.dropdownlistfor(m => m.countyid , new selectlist(model.counties), "countyid", "countyname "))

basically add together countyid main view model , when send form server match selected dropdown option.

.net asp.net-mvc api razor

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -