asp.net - MVC drop down list input post value and name -


i'm writing form uses drop down menus value selection. i'd know if possible post value , name of selectlist controller or add values every list item? need set lateralityid = value , lateralityname = text.

i'll post snippets of code idea across. model i'm using is

public class condition {     public string lateralityname { get; set; }     public string lateralityid { get; set; } } 

and values posted with

@html.dropdownlistfor( m => m.condition.lateralityid, getlateralities() ) 

where

    public static list<selectlistitem> getlateralities()     {         return new list<selectlistitem>         {             new selectlistitem { text = "",             value = "900" },             new selectlistitem { text = "left",         value = "1001" },             new selectlistitem { text = "right",        value = "1002" },             new selectlistitem { text = "midline",      value = "1003" },             new selectlistitem { text = "left midline", value = "1004" },             new selectlistitem { text = "right midline",value = "1005" },             new selectlistitem { text = "both sides",   value = "1006" },             new selectlistitem { text = "unknown",      value = "990" },             new selectlistitem { text = "unspecified",  value = "997" },             new selectlistitem { text = "n/a",          value = "999" },         };     } 

any appreciated. thanks!

solution stephen muecke

in controller use

lateralityname = getlateralities().firstordefault( x => x.value == m.condition.lateralityid )?.text; 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -