I’ve something similar to this:
public class employee
{
Int id;
String Name;
String FamilyName;
String SecondFamilyName;
}
public class orders
{
Int id;
Int employeeid;
Int amount;
}
(an employee can have many orders, orders and employee are related via “employeeid” property)
Strong-typed “create orders” form in MVC:
-
A DropDownList will allow me to select the right employee when creating orders.
-
The DropDownList should display employee names in a way defined by a third method, that it concatenates “FamilyName SecondFamilyName, Name” for employees that SecondFamilyName is not null and “FamilyName, Name” for the other.
What should I do? Using default VS 2010 templates, the runtime picks “Name” to show in DropDownList. I need the composite name, but I can’t figure how to it…
Regards.
Update 2,
After working for a couple of hours, I’ve noticed that, by default, VS 2010 generates a template which is being populated in Create method, with employees id and single names…
So,
Create method:
Create view:
replace server side code with
@Html.DropDownList(“employeeid”, String.Empty)
That’s all. I feel stupid not seeing this so-obvious-thing before…
What do you think, Dave A?
EDIT
Just adding the code used to build the list and the composite name:
–> Employee html helper, to generate SelectList (with selected item)
–> Employee extender, to get the composite name
Using Stringbuilder for performance