4
Hello! I have a little problem to make a selectlist display 2 values in textfield. I have the following Selectlist which is stored in a viewbag:
ViewBag.Account = new SelectList(new AccountBusiness().GetList<Account>(Util.AuxiliaryMethods.BMPerRequestInstance).ToList(), "AccountId", "AccountNumber");
In the DOM it displays the Accountnumber in the Option text and the Accountid in its value. On the screen it displays as follows:
I need it to display instead of just Accountnumber, also display one more field, which is Description, so it would be Accountnumber + Description, more or less like "15252 - Standart", and no value would continue to return Id. How can I make the Selectlist receive two parameters ?
Could concatenate the property
Description
with a separator and after obtaining the value made a split by the separator character (can be "-" or ";").– João Martins
The value that would be the Id I already got by the option Value, so the text I put in the option will not make a difference. So I guess I wouldn’t have to split to get it later, is that I’m getting the id by javascript. But about concatenating, I do it before sending to selectlist or after ?
– Dan Oliveira
I think it would be in the
SelectList
directly.– João Martins
But how would he do it ? I tried to get him to pass type 2 fields, using + "-" + but he understands it as if it were the name of the field. If I play "Accountnumber" + "-" + "Description" it looks exactly for that field. I don’t know much about concatenation as you can see Uahua if you can help me with example code
– Dan Oliveira