I'm trying to convert an ID into a name when I render a "detail" view in my application. I have successfully been able to display the name in my "edit" and "create" views by using the code:
In my controller:
ViewData["countyViewData"] = new SelectList(db.Counties, "CountyID", "CountyName");
In my views:
<%= Html.DropDownList("CountyID", ViewData["countyViewData"] as SelectList)%>
The heart of my question is what do I need in my controller and in my details view to display as the CountyName instead of the ID? I have this in the view currently:
<%= Html.Encode(Model.CountyID) %>
I assume I need some ViewData code in the controller to tell the view what county name to use for each ID.
Thanks in advance for helping a new programmer!
Added to Clarify: My Details view for a customer displays the value which is the CountyID, and I want it to display the CountyName which is stored in another table. What needs to be in the controller and the view so that the CountyName displays?