Saturday, 24 August 2013

How get value from cascading drop down list made with ajax

How get value from cascading drop down list made with ajax

I am very new too MVC, and have one problem. I am try to make cascading
drop down list using this example Easiest way to create a cascade dropdown
in ASP.NET MVC 3 with C#
But I am stuck a little bit, because I don't know how to get value and
send it to controller from second drop down, then I press button near it.
Here is my view:
<script type="text/javascript">
$('#list').change(function() {
var selectedClient = $(this).val();
if (selectedClient != null && selectedClient != '') {
$.getJSON('@Url.Action("SelectC")', { clientID: selectedClient
}, function (client) {
var campaingSelect = $('#clist');
campaingSelect.empty();
$.each(client, function(index, clients) {
campaingSelect.append($('<option/>', {
value: clients.value,
text: clients.text
}));
});
});
}
});
</script>
@using (Html.BeginForm("CreateNewCampaign", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.LabelFor(m => m.alreadyCreatedCampaignName, "Name:")
@Html.DropDownList("clist","-- Select Client -2-")
<input type="Submit" name="button" value="Select" class="btn
btn-primary" />
}
Controller:
public ActionResult SelectC(int clientId, CampaignModel model,
FormCollection form)
{
Session["ClientID"] = clientId;
ViewBag.ClientName = "You're using: " + Session["ClientName"];
var CampaignInf =
CampaignManagementService.GetCampaigns((string)
Session["ticket"], clientId);
List<AlreadyCreatedCampaignList> itemas = new
List<AlreadyCreatedCampaignList>();
foreach (var element in CampaignInf)
{
itemas.Add(new AlreadyCreatedCampaignList() {CampId =
element.Key, CampName = element.Value});
}
var listOfCam = new SelectList(itemas, "campID", "campName", 1);
return Json(listOfCam.Select(x => new {value = x.Value, text =
x.Text}), JsonRequestBehavior.AllowGet);
}
And like I say I whant get value to other controller, and i don't know ho
it should look like

No comments:

Post a Comment