Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. MVC4 Cascading DropDownList - reference selected value

MVC4 Cascading DropDownList - reference selected value

Scheduled Pinned Locked Moved ASP.NET
databaseasp-netsharepointcollaborationjson
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andy_L_J
    wrote on last edited by
    #1

    I have the following code in my MVC application to set up Cascading Drop Down Lists:

    public ActionResult Index(){
    ViewBag.Clubs = db.Clubs.OrderByDescending(c => c.Name).ToList();
    ViewBag.Comps = db.Competitions.OrderByDescending(c => c.StartDate).ToList();
    ViewBag.Teams = db.Teams.OrderBy(t => t.Name).ToList();
    return View();
    }

    public IList GetCompetitionList(int clubid)
    {...}

    public IList GetTeamList(int compid)
    {...}

    [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult LoadCompsByClubId(string clubid)
    {
    var compsList = this.GetCompetitionList(Convert.ToInt32(clubid));
    var compsData = compsList.Select(m => new SelectListItem(){
    Text = m.Name,
    Value = m.Id.ToString()
    });
    return Json(compsData, JsonRequestBehavior.AllowGet);
    }

    [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult LoadTeamsByCompId(string compid)
    {
    var teamsList = this.GetTeamList(Convert.ToInt32(compid));
    var teamsData = teamsList.Select(c => new SelectListItem(){
    Text = c.Division.Name,
    Value = c.Id.ToString()
    });
    return Json(teamsData, JsonRequestBehavior.AllowGet);
    }

    public ActionResult PlayerList(Team team)
    {
    if (team == null)
    {
    return HttpNotFound();
    }
    var players = from p in db.Sharks_Player
    join t in db.Sharks_Player_CompTeam
    on p.Id equals t.PlayerId
    orderby p.FirstName
    where t.CompTeam_Id == team.Id
    select p;
    return View(players);
    }

    And this is the .cshtml:

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups