Autopost back in mvc drop down list

前端 未结 4 837
借酒劲吻你
借酒劲吻你 2021-01-03 00:22

Requirment: I have a drop down list on my view page, displaying a list of vendors. When a vendor is selected from the dropdown, the page displays the details of selected ven

相关标签:
4条回答
  • 2021-01-03 00:39

    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.
    });
    
    0 讨论(0)
  • 2021-01-03 00:42

    You can do it by this way:

    @Html.DropDownList("VendorList", @Model.vendorSelectList, "--Select Vendor--", new { @onchange = "this.form.submit();" })
    
    0 讨论(0)
  • 2021-01-03 00:43

    Change the dropdown instantiation to this

    @Html.DropDownList("VendorList", @Model.vendorSelectList, new { onchange = "$(this).parent('form:first').submit();" }})
    
    0 讨论(0)
  • 2021-01-03 00:54

    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
    
    0 讨论(0)
提交回复
热议问题