0

In a view of ClimateChartController I do this code:

@Html.ActionLink("Kies land", "ListCountries", "Continent" new {Selectedyear = @ViewBag.SchoolYear, continentId = @ViewBag.ContinentId})

So this should go to the method ListCountries of ContinentController, along with the given parameters.

Now this doesn't work, if I do it without the parameters it goes to the method but well, I need the parameters...

For now I resolved this by using the following method in ClimateChartController:

public ActionResult ListCountries(int selectedyear, int continentid)
        {
            return RedirectToAction("ListCountries", "Continent",
                new { selectedYear = selectedyear, continentId = continentid });
        }

This works as intended, but causes cluttering of code and isn't neat.

So how can I call a method of another controller and pass some parameters with it?

1 Answers1

0

Try this:

@Html.ActionLink("Kies land", "ListCountries", "Continent" , null, new {Selectedyear = @ViewBag.SchoolYear, continentId = @ViewBag.ContinentId})

OR:

Html.ActionLink("Kies land", "ListCountries", "Continent", new {Selectedyear = @ViewBag.SchoolYear, continentId = @ViewBag.ContinentId}, null)

There are possible solutions here:

Why does Html.ActionLink render "?Length=4"

Community
  • 1
  • 1
Dawood Awan
  • 7,051
  • 10
  • 56
  • 119
  • I alrey tried the first solution u gave, which didn't work, the second one does, thanks! –  Mar 18 '15 at 10:21