I am new to MVC and View Models, and trying to wrap my thoughts on how it all works and ties together. I am trying to populate a State dropdown in an Address table. I have a States table with StateAbbr and StateName. What I would like to do is display StateName and save StateAbbr in the Address table. I have been working in the Address Create view. I have tried a number of ways and nothing seems to work so I thought I would just ask the question. My main way of doing it was through Ajax however it would display the StateName but save a Null and was told not to do it this way. Then thought to do it through a ViewModel which I have set up with IEnumerable however I am not sure how to implement it from there.
Asked
Active
Viewed 91 times
0
-
Without showing your current implementation(ONLY relevant code), It is hard to tell what is wrong – Shyju Jul 20 '16 at 15:38
-
ViewModel with IEnumerable sounds good. Use `@Html.DropdownList` to render the options. – Georg Patscheider Jul 20 '16 at 15:40
-
How do you use a created viewModel in a @Html.DropdownList – Ethel Patrick Jul 20 '16 at 15:55
-
@EthelPatrick I hope [Best programming practice of using DropDownList in ASP.Net MVC](http://stackoverflow.com/a/37819577/296861) will help you get started. – Win Jul 20 '16 at 16:08
-
I can get the dropdown to populate with the StateName however how do I get the StateAbbr to the public ActionResult Create([Bind(Include="AddressID,PersonID,Address1,Address2,City,StateAbbr,Zip")] Address address) – Ethel Patrick Jul 20 '16 at 16:54