c# - Concatenate two columns in drop down list in MVC4 -


i have 3 columns in table (see below) , want concatenate 2 , 3 column text , column 1 value. how can in mvc dropdown?

category table  id    categoryname categoryname_en  1    abc           abc  2    xyz           xyz  3    efg           efg 

dropdown list needs looks like

dropdownlist text     value                   abc/abc   1              xyz/xyz   2              efg/efg   3 

it below:

 public ienumerable<selectlistitem> getcategorylist(int selectedcatid)  {         // assuming getcategoriesfromdb returning ienumerable of category      return getcategoriesfromdb()                         .select(cat =>                             selectlistitem                            {                                text = cat.categoryname + "/" + cat.categoryname_en,                                value = cat.id,                                selected = selectedcatid == cat.id                              }).tolist();  } 

you can use method , send selected category id make sure correct item selected.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -