Click here to Skip to main content
15,072,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I'm new to MVC.
I have two drop-downs when we are selecting the first one we need to update the second one.
Below is my view
@model HostingManager.Models.ContractManager
@{
ViewBag.Title = "CustomCreate";
}

@Html.Partial("_GroupDDL" , Model)



@Html.Partial("SelectClient", Model)



@Html.Partial("SelectContract", Model)


Below is first Drop-down(Partial View:_GroupDDL)
@model HostingManager.Models.ContractManager

@using (Ajax.BeginForm("SelectClient", "Contracts", new AjaxOptions { UpdateTargetId = "IClients" }))
{
@Html.DropDownListFor(
m => m.SelectedGroupId,
new SelectList(Model.IGroups, "id", "name"),
string.Empty
)
}
<script type="text/javascript">
$('#SelectedGroupId').change(function () {
$(this).parents('form').submit();
});
</script>

Below is Second Drop-down(Partial View : SelectClient)
@model HostingManager.Models.ContractManager

@if (Model.IClients != null && Model.IClients.Count() > 0)
{
using (Ajax.BeginForm("SelectContracts", "Contracts", new AjaxOptions { UpdateTargetId = "IContracts" }))
{
@Html.HiddenFor(m => m.SelectedGroupId)
@Html.DropDownListFor(
m => m.SelectedClientId,
new SelectList(Model.IClients, "id", "cname"),
string.Empty
)
}
}

<script type="text/javascript">
$('#SelectedClientId').change(function () {
$(this).parents('form').submit();
});
</script>

Below is my Controller action
public ActionResult CustomCreate()
{
ContractManager CM = new ContractManager();
CM.IGroups = db.groups.ToList();
return View(CM);
}

[HttpPost]
public ActionResult SelectClient(int? SelectedGroupId)
{
ContractManager CM = new ContractManager();
CM.IClients = new List<clients>();
if (SelectedGroupId.HasValue)
{
CM.IClients = db.client.ToList();
}
return PartialView("SelectClient", CM);
}
Now The problem:
In Debugging Mode when I'm selecting the first DDL..Control is coming to second DDL with the values but the Second DDL is not appearing on the View.I mean on UI we can't see the Second DDL.

As per My Code It is calling the SelectClient of Controller but my Main View is not updating with the updated partial view.

Can anybody plz tell where the problem is..
I already added ajax script in my Layout and also enabled in web.config
I'll filter the Second DDL the Once if I can overcome this.

Thanks in Advance
Posted
Updated 7-Apr-13 3:18am
v5
Comments
Member 7676955 7-Apr-13 10:57am
   
In My posted code everything is working well but the Second Drop down box is not displaying while excution completes..
Member 7676955 8-Apr-13 2:06am
   
Can Anybody help me on this.. It is still not fixed :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900