在ClimateChartController的视图中,我执行以下代码:
@Html.ActionLink("Kies land", "ListCountries", "Continent" new {Selectedyear = @ViewBag.SchoolYear, continentId = @ViewBag.ContinentId})
所以这应该转到ContinentController的ListCountries方法,以及给定的参数。
现在这不起作用,如果我在没有参数的情况下这样做,那么我需要参数......
现在我通过在ClimateChartController中使用以下方法解决了这个问题:
public ActionResult ListCountries(int selectedyear, int continentid)
{
return RedirectToAction("ListCountries", "Continent",
new { selectedYear = selectedyear, continentId = continentid });
}
这可以按预期工作,但会导致代码混乱并且不整洁。
那么如何调用另一个控制器的方法并用它传递一些参数?
答案 0 :(得分:0)
试试这个:
@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)
这里有可能的解决方案: