开发者

Get value from Entity Framework for Dropdown List and Return selected value in MVC

开发者 https://www.devze.com 2023-03-21 04:24 出处:网络
Assuming i got a table called Countries and using Entity Framework, i want to know how could i populate the available countries (listed in the table countries) to view as drop down list and return the

Assuming i got a table called Countries and using Entity Framework, i want to know how could i populate the available countries (listed in the table countries) to view as drop down list and return the value to HTTPPost Controller

i got

public ActionResult SignUp() 
i think the populate code should be here but i not sure 
how to retrieve from entity framework and populate into view

and

 [httpPost]
 public ActionResult SignUp()
 i want to read the user selected value and i think is 
 int value = form["DropDownListName"].SelectedIndex + 1;

can anyone please guide me on this with some hint or example , please ? T开发者_如何学编程hx a lot =D


To be honest, you're not really working in an MVC pattern here. Don't put UI construction logic in your constructor.

Rather, expose the ID that you want to bind to the list via a model that you pass to a View() method in your constructor.

In your view, use the name of that property as the Name of a Drop-down and create a helper class to generate the list of values.

I'd give you a more specific example, but I'm in the cinema with my iPad, so a bit stuck for access to Visual Studio at the moment!

0

精彩评论

暂无评论...
验证码 换一张
取 消