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
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.
});
You can do it by this way:
@Html.DropDownList("VendorList", @Model.vendorSelectList, "--Select Vendor--", new { @onchange = "this.form.submit();" })
Change the dropdown instantiation to this
@Html.DropDownList("VendorList", @Model.vendorSelectList, new { onchange = "$(this).parent('form:first').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