Autopost back in mvc drop down list

♀尐吖头ヾ 提交于 2019-11-30 14:30:56

There is no AutoPostback=true in MVC. You will have to wire this up yourself. You can do something like this, using jQuery:

$("#idOfMyDropDownList").change(function () {
    // Handle the change event, such as fire off an ajax request.
});

Change the dropdown instantiation to this

@Html.DropDownList("VendorList", @Model.vendorSelectList, new { onchange = "$(this).parent('form:first').submit();" }})

You can do it by this way:

@Html.DropDownList("VendorList", @Model.vendorSelectList, "--Select Vendor--", new { @onchange = "this.form.submit();" })

Assuming you will need to do a database hit to get the results, inside James D'Angelo'a jquery function you would then do a .post on the vendor details method in your controller to get your object back and then you populate the details for the selected vendor to the page. You will have to add a method to the controller that returns a json object

$.post("/{Controller}/{Method}", { VendorId: selectVal }, function(response, status) {
    var vendorDetails = eval("(" + response + ")");
    //additional code to populate the fields
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!