在控制器中单击的 MVC 请求操作链接
MVC Request Actionlink that was clicked in controller
我有执行类似功能的操作链接。我如何请求刚刚在控制器中单击了哪个操作链接,以便我可以将它们全部放在同一个 TopRated
函数中,如下所示:
@Html.ActionLink("Today", "TopRated")
@Html.ActionLink("30 Days", "TopRated")
@Html.ActionLink("Weekly", "TopRated")
@Html.ActionLink("All Time", "TopRated")
而不是像这样在 4 个不同的函数中使用它们:
@Html.ActionLink("Today", "Today")
@Html.ActionLink("30 Days", "TopRated30")
@Html.ActionLink("Weekly", "TopRatedWeekly")
@Html.ActionLink("All Time", "AllTimeTopRated")
控制器:
public ActionResult TopRated()
{
using (var context = new EntityDBContext())
{
//Request which actionlink was just clicked by user
}
}
创建所有评分最高时段的枚举器:
public enum PeriodEnum
{
Today,
ThirtyDays,
Weekly,
AllTime
}
您的 TopRated
应该收到您之前创建的枚举类型的参数:
public ActionResult TopRated(PeriodEnum period)
{
using (var context = new EntityDBContext())
{
//Request which actionlink was just clicked by user
}
}
最后,您的操作链接将如下所示:
@Html.ActionLink("Today", "TopRated", new {period = PeriodEnum.Today})
@Html.ActionLink("30 Days", "TopRated", new {period = PeriodEnum.ThirtyDays})})
@Html.ActionLink("Weekly", "TopRated", new {period = PeriodEnum.Weekly})
@Html.ActionLink("All Time", "TopRated", new {period = PeriodEnum.AllTime})
我有执行类似功能的操作链接。我如何请求刚刚在控制器中单击了哪个操作链接,以便我可以将它们全部放在同一个 TopRated
函数中,如下所示:
@Html.ActionLink("Today", "TopRated")
@Html.ActionLink("30 Days", "TopRated")
@Html.ActionLink("Weekly", "TopRated")
@Html.ActionLink("All Time", "TopRated")
而不是像这样在 4 个不同的函数中使用它们:
@Html.ActionLink("Today", "Today")
@Html.ActionLink("30 Days", "TopRated30")
@Html.ActionLink("Weekly", "TopRatedWeekly")
@Html.ActionLink("All Time", "AllTimeTopRated")
控制器:
public ActionResult TopRated()
{
using (var context = new EntityDBContext())
{
//Request which actionlink was just clicked by user
}
}
创建所有评分最高时段的枚举器:
public enum PeriodEnum
{
Today,
ThirtyDays,
Weekly,
AllTime
}
您的 TopRated
应该收到您之前创建的枚举类型的参数:
public ActionResult TopRated(PeriodEnum period)
{
using (var context = new EntityDBContext())
{
//Request which actionlink was just clicked by user
}
}
最后,您的操作链接将如下所示:
@Html.ActionLink("Today", "TopRated", new {period = PeriodEnum.Today})
@Html.ActionLink("30 Days", "TopRated", new {period = PeriodEnum.ThirtyDays})})
@Html.ActionLink("Weekly", "TopRated", new {period = PeriodEnum.Weekly})
@Html.ActionLink("All Time", "TopRated", new {period = PeriodEnum.AllTime})