'How to get the selected value of a DropDownList in controller (MVC)
I have two dropdown list that value get from database, second dropdown list (Recver) is depend on first dropdown list choice , how to get the first dropdown list (RecvCom) value when user have pick one ?
in my view ,
<div class="col-xl-4 col-md-6 col-12">
<div class="row">
<div class="col-xl-4 col-md-4 col-12 form-title">
Receive Company
</div>
<div class="col-xl-8 col-md-8 col-12 form-data">
@Html.DropDownList("RecvCom", "Please choose")
@*@Html.TextBoxFor(model => model.RecvCom, new { placeholder = ModelsAttributeHelper<SubMIS.Models.RecvCom>.GetDisplayName("RecvCom") })*@
@Html.ValidationMessageFor(model => model.RecvCom)
</div>
</div>
</div>
<div class="col-xl-4 col-md-6 col-12">
<div class="row">
<div class="col-xl-4 col-md-4 col-12 form-title">
@Html.LabelFor(model => model.Recver)
</div>
<div class="col-xl-8 col-md-8 col-12 form-data">
@Html.DropDownList("Recver", "Please choose")
@*@Html.TextBoxFor(model => model.Recver, new { placeholder = ModelsAttributeHelper<SubMIS.Models.Recver>.GetDisplayName("Recver") })*@
@Html.ValidationMessageFor(model => model.Recver)
</div>
</div>
</div>
in my macontroller,
ViewBag.RecvCom = new SelectList(_db.Members.Where(p=>p.TradeName != null).Select(p => p.TradeName).Distinct());
how to get the first dropdown list (RecvCom) value when user have pick one ?
Solution 1:[1]
If you wish to learn more about MVC there is lessons I found very helpful on Udemy . This user created a video course on creating a shopping cart application that uses model views is .net c# . follow this users guide to fully understand .net this is the users lessons : https://www.udemy.com/course/aspnet-mvc-5-project-cms-and-shopping-cart-with-paypal/
he has explained in creating a category how to implement items into a drop down list and add new items to that list. also the list can be selected from.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thaveshan Naidoo |
