Last post Jul 20, 2017 01:45 PM by nathan.shull
Jul 19, 2017 03:36 PM|nathan.shull|LINK
I'm currently in the process of converting my webform .aspx page into a view on my MVC project. In my webform application, the dropdown was very simple:
<asp:DropDownList ID="divisions" runat="server">
<asp:ListItem Text="Advantage" Value="P" />
<asp:ListItem Text="ADVOC" Value="J" />
and then to get the value of which division was selected, I used divisions.SelectedValue. What would be the equivalent of this in MVC? Thanks!
Jul 19, 2017 03:48 PM|A2H|LINK
You have multiple options. You can use HTML Select or Dropdownlist Helper class in mvc.
Take a look at this url for more details
Jul 19, 2017 07:42 PM|codemovement.pk|LINK
For binding please follow following link
Jul 19, 2017 08:07 PM|nathan.shull|LINK
Thank you for the help. I've gotten a dropdown as you've described above, but I'm still unable to get the value of the selected option back in my controller. Any help?
Jul 20, 2017 01:40 AM|vitomanj|LINK
While it may seem a little overkill, I decided to write a series on using ASP.NET MVC Dropdown lists and all of the possible combinations we use them in our UI.
Hope this helps.
Jul 20, 2017 06:48 AM|Jean Sun|LINK
Do you mean that you want to get the selected option in controller? Controller can get the select's value by its name. So, you can set name to select. I made a sample, you can take it as a reference.
Code in View:
ViewBag.Title = "Home Page";
<select name="select" id="divisions" class="form-control">
<input type="submit" />
Code in Controller:
public ActionResult Index(string select)
I set a breakpoint in Controller, when I select Advantages and submit it, we can see that:
And you can share your code here, so we can check what's wrong with your code.
Jul 20, 2017 01:45 PM|nathan.shull|LINK
This was exactly what I needed! I know, super simple, but I just couldn't figure it out as I'm just starting with MVC. Anyway, thank you so much!!