I am new with MVC I am trying to create a small product form with TextBox and DropDownList field, I have created a Class in Model with personName, productName. I have only 5 Products so I don’t want to use db for it.
I tried all that I can by doing google but still not able to get my dropdown list
Thanks
Assuming you have a
PersonsProductclass to represent your model/viewmodel like thisIn your
GETaction method, you may initialize the values like thisAnd in your View which is strongly typed to
PersonsProductviewmodelAnd in your
HTTPPostaction, you can get the selected productId like thisNEVER HARDCODE LIKE THIS. It is UGLY UGLY UGLY !
This answers your question (without using Database and XML). But I strongly recommend to avoid this hardcoding approach. You should better use different source for the list of products like database / XML file etc.. Otherwise whenever you want to add a new product to the list, you need a recompilation. I hope you will change this code to read Product data from a different source instead of hard coded values.