inforakesha

A fine WordPress.com site

Using JQuery for Controller method cal and loading partial view dynamically

Leave a comment

for first dropdown in Controller

publicActionResultStore()
{
UserInfoService.UserInfoClientproxy=newUserInfoService.UserInfoClient();

ViewBag.CityList=newSelectList(proxy.GetCity());
string[]CityList=proxy.GetCity();

returnView(CityList);
}

in View

@Html.DropDownList("CityList",ViewBag.CityListasSelectList,"SelectCity",new{id="CityList1"})

now define another action for 2nd dropdown list

publicActionResultstoreList(stringCity)
{
UserInfoService.UserInfoClientproxy=newUserInfoService.UserInfoClient();

IEnumerable<Stores>Store=proxy.GetStoreByCity(City);
ViewBag.StoreList=fromsinStore
selectnewSelectListItem{Text=s.Name,Value=Convert.ToString(s.Id)};

returnPartialView("_StoreList");

}

create a partial view
@Html.DropDownList("StoreList",ViewBag.StoreListasSelectList,"selectstore",new{id="storelist1"})

in view
<scripttype="text/javascript">
$(function(){
$('#CityList1').change(function(){
varc=$('#CityList1').val();
//$('#partialDropDown').load('@Url.Action("storeList","User")',{city:c});
//get or post both will work
$.get("/User/storeList",{city:c},
function(data){
$("#UpdateableContent").html(data);
});

alert($('#CityList1').val());
});
})

</script>

in main VIew
<divid="UpdateableContent">
@*@Html.Partial("_PartialView1")*@
</div>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s