简体   繁体   English

如何在控制器(MVC)中获取 DropDownList 的选定值

[英]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 ?我有两个从数据库中获取值的下拉列表,第二个下拉列表(Recver)取决于第一个下拉列表选择,当用户选择一个时如何获取第一个下拉列表(RecvCom)值?

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 ?当用户选择一个时如何获取第一个下拉列表(RecvCom)值?

If you wish to learn more about MVC there is lessons I found very helpful on Udemy .如果您想了解有关 MVC 的更多信息,我发现 Udemy 上的课程非常有用。 This user created a video course on creating a shopping cart application that uses model views is .net c# .该用户创建了一个关于创建使用模型视图的购物车应用程序的视频课程是 .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/遵循此用户指南以充分了解 .net 这是用户的课程: 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.也可以从中选择列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM