asp.net - @Html.DropDownListFor error -


i having function returns

> ienumerable<selectlistitem>  public ienumerable<selectlistitem> listitems     { 

using

@html.dropdownlistfor( m=>model.listitems) having error message  

error 1 no overload method 'dropdownlistfor' takes 1 arguments

however, works fine @html.dropdownlist("listitems", model.listitems)

why having error message @html.dropdownlistfor?

there no overloads satisfy parameters. in other words, there's no method html.dropdownlistfor() accepts selectlistitem.

http://msdn.microsoft.com/en-us/library/system.web.mvc.html.selectextensions.dropdownlistfor.aspx

try this:

public class yourviewmodel {      public selectlist yourselectlist { get; set; }      public string selecteditem { get; set; } } 

then in view:

@html.dropdownlistfor(c=>c.selecteditem, model.yourselectlist) 

when form posted, selecteditem hold whichever item selected in dropdown list.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -