integrating jquery with AJAX using MVC for ddl/html.dropdownlist
Posted
by
needhelp
on Stack Overflow
See other posts from Stack Overflow
or by needhelp
Published on 2009-05-01T05:09:44Z
Indexed on
2012/09/15
21:39 UTC
Read the original article
Hit count: 186
the situation: a user on the page in question selects a category from a dropdown which then dynamically populates all the users of that category in a second dropdown beside it.
all the data is being retrieved using LinqtoSQL and i was wondering if this can be done a) using html.dropdownlist in a strongly typed view? b) using jquery to trigger the ajax request on selected index change instead of a 'populate' button trigger?
sorry i dont have code as what i was trying really wasnt working at all. I am having trouble with how to do it conceptually and programatically!
will appreciate any links to examples etc greatly!
thanks in advance!
EDIT:
this is kind of what i was trying to achieve.. first the ViewPage:
<script type="text/javascript">
$(document).ready
function TypeSearch() {
$.getJSON("/Home/Type", null, function(data) {
//dont know what to do here
});
}
</script>
<p>
<label for="userType">userType:</label>
<%= Html.DropDownList("userType") %>
<%= Html.ValidationMessage("userType", "*") %>
<input type="submit" runat="server" onclick="TypeSearch()" />
<label for="accountNumber">accountNumber:</label>
<%= Html.DropDownList("accountNumber") %>
<%= Html.ValidationMessage("accountNumber", "*") %>
</p>
Then home controller action:
public ActionResult Type()
{
string accountType = dropdownvalue;
List<Account> accounts = userRep.GetAccountsByType(accountType).ToList();
return Json(accounts);
}
© Stack Overflow or respective owner