bastijn
bastijn

Reputation: 5953

Fill textboxes based upon current Dropdownlist (database items) selection (asp.NET MVC)

I have a dropdown box in my view which is populated with objects from database. Now what I want to do is, based upon selection in the Dropdown fill various textboxes with property values of the object selected in the dropdownlist.

There are numerous examples where you copy the selected dropdown value in the textbox using JQuery / JavaScript etc, but I can't find any doing the same but instead of copying; place the values of the properties of the object in the textboxes.

How would this be done in a nice way? I would prefer to do it without posting the entire form, though those answers may be posted also.

Upvotes: 0

Views: 1970

Answers (1)

Alex
Alex

Reputation: 35409

 $('select#yourControlId').change(function () {
    var selectedVal = $(this).val();

    document.location = '<%= Url.Action( "Action", "Controller") %>' + '?val=' + selectedVal;
 });

Then you'll capture val in the signature of teh action method and populate the appropriate textboxes...

Or

You could also on Changed do a JQuery Ajax post...

http://api.jquery.com/jQuery.ajax/

Upvotes: 1

Related Questions