从下拉列表中显示成员和值成员

时间:2014-02-14 06:49:51

标签: asp.net asp.net-mvc-4 razor

我正在学习MVC 4剃须刀,我试图从下拉列表中获取显示成员和值,但我无法得到它,这是我的代码

   <script src="~/Scripts/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).change(function ()
    {
        var selectedItem = $("#Employee :selected").text();
        var selectedValue = $("#Employee").val();
        alert(selectedItem+" "+selectedValue);
        //document.getElementById("#lblEmployee").innerText = selectedItem;
    });

</script>
@Html.DropDownList("Employee", ViewData["lstEmp"] as SelectList)

请帮助我,如果有任何其他方式而不是使用JQuery请告诉。

1 个答案:

答案 0 :(得分:0)

iSpeechIntent.putExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES, true);

查看模型:

Controller:
    public ActionResult Create()
        {
        var VM = new ProjectViewModel();
        int projectId = 0;

        var list = new List<SelectListItem>();

list.Add(new SelectListItem { Value = "1", Text = "a" });
list.Add(new SelectListItem { Value = "2", Text = "b" });
list.Add(new SelectListItem { Value = "3", Text = "c" });

            VM.ddlClientLists = list
            return View("Create",VM);
        }
创建视图中的

  public class VM
    {
        public List<SelectListItem> ddlClientLists { set; get; }
        public VM(){
            ddlClientLists = new List<SelectListItem>();          
        }
    }