Multiple Values ​​in SelectList Text

I am trying to show several values ​​in the text dropdownlist. An example is given below.

SelectList(Parts, "pno", "pcode"+"pname")

Where

pno - detail number.

pcode - part code.

pname is the name of the part

Now, please tell me how I can concatenate the code and part name using the viewmodel (I want to do this using the domain model).

+5
source share
2 answers

According to the Microsoft documentation, SelectList (IEnumerable, String, String) Initializes a new instance of the SelectList class using the specified elements for the list, data value field, and data field.

http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist%28v=vs.108%29.aspx

, . 8 ups - .

SelectList?

:

public class Model
{
    public string pcode { get; set; }
    public string pname { get; set; }
    public string ConcatDescription { get; set; }

    public string ConcatDescription 
    {
        get 
        {
            return string.Format("{0} {1}", pcode , pname );
        }
    }
}

.

SelectList(Parts, "pno", "ConcatDescription ")

EDIT: .

+8

, . # ,

public class Parts
{
    public string PartCode { get; set; }

    public string PartName { get; set; }

    public string PartNo
    {
        get
        {
            return PartCode + PartName;
        }
        set;
    }
}

, .

SelectList(Parts, "PartNo")
+3

All Articles