本文介绍了如何在Mvc中获取选定值,下拉列表的选定索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello House,



i来自asp.net拖放背景,我希望能够获得下拉列表的选定值,选定索引等控制mvc5中的控制器代码。这是我的查看代码:



Hello House,

i came from asp.net drag and drop background, i want to be able to get the selected value, selected index etc of a drop downlist control in the controller code in mvc5. here is my view code:

@Html.DropDownList("Role",new List<SelectListItem>
                        {
                             new SelectListItem{Text="Select Role", Value="0",Selected =true } ,
                            new SelectListItem{Text="Student", Value="1" } ,
                            new SelectListItem{Text="Lecturer", Value="2"  }

                        }, "") 





任何帮助将不胜感激。



Any assistance will be appreciated.

推荐答案

@model ViewModel.someViewModel
 @Html.DropDownListFor(model => model.ID, new SelectList(ViewBag.Roll, "ID", "Name"))

then in your controller action method should receive  data

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Update(viewModel model)
{
//do some thing
}


这篇关于如何在Mvc中获取选定值,下拉列表的选定索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 11:34