Geting SelectList to MVC view using AJAX/jQuery
Posted
by Chris
on Stack Overflow
See other posts from Stack Overflow
or by Chris
Published on 2010-03-12T00:51:57Z
Indexed on
2010/03/12
0:57 UTC
Read the original article
Hit count: 871
Hi all.
I have a C# MVC application which is populating a dropdown based on a date selected. Once the date is selected I am sending it to an action via AJAX/jQuery. The action gets a list of items to return for that date.
Here is where my problem is. I have done it previously where I render a partial view from the action and pass it the SelectList as the model. However, I really just want to do it inline in the original view, so I'm hoping there is some way I can return the SelectList and from there do some magic Javascript/JQuery to put it into a dropdown.
Has anybody ever done this before? If so, what do I on the client end after calling the load() to return the SelectList?
I've done something like this previously, when I was just returning a string or other value to be rendered as straight text:
$("#returnTripRow").load("/Trip.aspx/GetTripsForGivenDate?date=" + escape(selection));
But I'm not sure how to intercept the data and morph it into am Html.DropDown() call, or equivalent.
Any ideas?
Thanks,
Chris
© Stack Overflow or respective owner