I am trying to show multiple values in dropdownlist text. The example is given following.
SelectList(Parts, "pno", "pcode"+"pname")
where
pno is Part number.
pcode is part code.
pname is part name
Now please tell me how can i concatenate part code and name with out using viewmodel(I want to do it using domain model).
According to microsoft documentation, SelectList(IEnumerable, String, String) Initializes a new instance of the SelectList class by using the specified items for the list, the data value field, and the data text field.
http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist%28v=vs.108%29.aspx
In order to do this, you would want to concatenate the name into a new property on your model. The below stack overflow answer with 8 ups is my favorite way to do this.
How can I combine two fields in a SelectList text description?
In your case, it would look something like this…
Then you can just call that property directly.
EDIT: Added in code for clarification.