Please give me sample code or correct my code if any one have solution for how to make Cascade dropdown list with MVC razor by using entity framework. My code is
Controller:
public ActionResult Index(string MatchTypeName, string CompetitionName, string MatchName, string GroundName, string ReportName)
{
foreach (WebReportType WebRepots in db.WebReportTypes)
{
SelectListItem selectReportType = new SelectListItem
{
Text = WebRepots.ReportName,
Value = WebRepots.ReportName,
};
SelectReports.Add(selectReportType);
ViewBag.ReportName = SelectReports;
}
foreach (MatchTypeMaster MatchType in db.MatchTypeMasters)
{
SelectListItem selectMatchTypes = new SelectListItem
{
Text = MatchType.MatchTypeName,
Value = MatchType.MatchTypeID,
};
selectMatchTypeList.Add(selectMatchTypes);
ViewBag.MatchTypeName = selectMatchTypeList;
}
foreach (Competition CompMatchType in db.Competitions)
{
SelectListItem selectCompetitionTypes = new SelectListItem
{
Text = CompMatchType.CompetitionName,
Value = CompMatchType.CompetitionID,
};
selectCompetitionList.Add(selectCompetitionTypes);
ViewBag.CompetitionName = selectCompetitionList;
}
foreach (Match Match in db.Matches)
{
SelectListItem selectMatch = new SelectListItem
{
Text = Match.MatchName,
Value = Match.MatchID,
};
selectMatchList.Add(selectMatch);
ViewBag.MatchName = selectMatchList;
}
foreach (Ground Ground in db.Grounds)
{
SelectListItem selectGround = new SelectListItem
{
Text = Ground.GroundName,
Value = Ground.GroundID,
};
selectGroundList.Add(selectGround);
ViewBag.GroundName = selectGroundList;
}
View:
@Html.DropDownList("ReportName", ViewData["ReportName"] as MultiSelectList, new { multiple = "multiple", @class = "multiselect" , style = "width: 400px"})
@Html.DropDownList("MatchName", ViewData["MatchName"] as MultiSelectList, new { multiple = "multiple", @class = "multiselect" , style = "width: 400px"})
@Html.DropDownList("MatchTypeName", ViewData["MatchTypeName"] as MultiSelectList, new { multiple = "multiple", @class = "multiselect" })