entity framework 4 - Asp.Net mvc 2 , DropDownListFor and Editor Template . Selected Value dosen't work -


i have 2 views. productform.aspx , category.ascx. categoryform partial view. call category.ascx productform editorfor(model => model.category) . in partial view, there dropdownlistfor category. problem selected value specific product category. selected value dosen't work.

why ?


here have in productform

<div class="editor">           <div class="editor-label">         <%: html.labelfor(model => model.productinfo.productname) %>     </div>      <div class="editor-field">         <%: html.textboxfor(model => model.productinfo.productname)%>         <%: html.validationmessagefor(model => model.productinfo.productname)%>     </div> </div> <%: html.editorfor(model => model.productinfo.category, new { categorylist = model.categorylist })%> 


in category.ascx

<div class="editor-field">    <%:html.dropdownlistfor(model => model.categoryid, (ienumerable<selectlistitem>)viewdata["categorylist"])%> </div> 

you can assign name attribute of ddl whatever categoryid/foreign key called in products table. ddl automatically select category, due how default binding works.

one example:

<%: html.dropdownlist("book.genreid" , model.genresselectlist )%> 

and resulting html:

<select id="book_genreid" name="book.genreid"> <option value="2">horror</option> <option selected="selected" value="3">literature</option> <option value="1">science fiction</option> </select> 

or:

<%: html.dropdownlistfor(model => model.book.genreid, model.genresselectlist )%> 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -