Handling onchange event in HTML.DropDownList Razor MVC

后端 未结 2 1208
旧巷少年郎
旧巷少年郎 2020-12-05 17:37

I\'m handling an onchange event with a selected value by simple HTML like this:


                        
    
提交评论

  • 2020-12-05 17:59

    The way of dknaack does not work for me, I found this solution as well:

    @Html.DropDownList("Chapters", ViewBag.Chapters as SelectList, 
                        "Select chapter", new { @onchange = "location = this.value;" })
    

    where

    @Html.DropDownList(controlName, ViewBag.property + cast, "Default value", @onchange event)
    

    In the controller you can add:

    DbModel db = new DbModel();    //entity model of Entity Framework
    
    ViewBag.Chapters = new SelectList(db.T_Chapter, "Id", "Name");
    
    0 讨论(0)
  • 提交回复
    热议问题