function GetFormValues() {
var fv =
{ "AreaId": $("#Area").val(),
"RegionId": $("#RegionId").val()
}; return fv;
}
// Change event handler to the first drop down ( Country List )
$("#Area").change(function() {
$.ajax({
type: 'GET',
url: "@Url.Action("Edit", Url.RequestContext.RouteData.Values)" + "?area=" + $("#Area").val(),
data: GetFormValues()
});
nissan
Participant
1065 Points
618 Posts
ViewDate qn
Mar 09, 2012 08:19 PM|LINK
I have this code in my controller, my ViewData["RegionId"] should be updated when the #Area changes value..
[HttpGet]
public ActionResult Edit(int id, int? area)
{
if(area != null)
{
ViewData["RegionId"] = GetRegion(area);
}
else
{
ViewData["RegionId"] = 12;
}
}
This on the cshtml
function GetFormValues() {
var fv =
{ "AreaId": $("#Area").val(),
"RegionId": $("#RegionId").val()
}; return fv;
}
// Change event handler to the first drop down ( Country List )
$("#Area").change(function() {
$.ajax({
type: 'GET',
url: "@Url.Action("Edit", Url.RequestContext.RouteData.Values)" + "?area=" + $("#Area").val(),
data: GetFormValues()
});
<b>Region:</b> @ViewData["RegionId"]
------------------------------------------------------
My ViewDate["regionId"] is not changing on the change function of #Area. What am I missing?
ignatandrei
All-Star
134983 Points
21638 Posts
Moderator
MVP
Re: ViewDate qn
Mar 10, 2012 02:09 AM|LINK
please see
http://bit.ly/mvc_ajax_jquery
to return data from ajax.
bruce (sqlwo...
All-Star
36850 Points
5445 Posts
Re: ViewDate qn
Mar 10, 2012 02:31 AM|LINK
you do not have any code in the change function to change it. the ajax call calls the server and does nothing with the response.