0

I am new to MVC. i want call database on dropdown value change. Does anybody know how to do that.

Regards, vangli

1

2 Answers 2

0

MVC does not have a post-back mechanism as such as you had in WebForm (well, this was being carried out as javascript posting the form.

What you can do is create some javascript using jquery if you want to trigger some action when the item in that dropdown changes. it would be, (assuming the id of the dropdown is idDropDown

$('#idDropDown').change(function () {
    $.ajax(@Url.Action("AjaxAction", "MyController")', { selection : selectedValue }, function (data)){
        //handle ajax response here
    };
});

Your action controller will be like this:

public ActionResult AjaxAction(string selection)
{
    // do your server-side processing and get your data
    return Json(data);
}
Sign up to request clarification or add additional context in comments.

Comments

0

With out jquery you can POST the data to controller action using pure java script.

@Html.DropDownListFor(m => m.SelectedValue,Model.SelectListItems,new{ onchange = "this.form.submit();" })

Note: Here simply you can submit form by adding java script code to on change. This is similar that you click on submit button.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.