0
我有一个MVC .Net C#项目。在主控制器下有计划行动。 但我不想访问此页作为http://....../Home/Plans 但我想访问它作为http://....../Plans 但我不想创建计划控制器。所以我不想做一个redirectToAction。简单的路由到另一个控制器的动作
我试图使用Route Annonation如下所示:
[Route("plans/")]
public ActionResult Plans()
[Route("plans/{actions}")]
public ActionResult Plans()
[Route("plans/index")]
public ActionResult Plans()
但没有上述工作对我来说。你们能帮助我吗?
更新时间:
这是我的HomeController
[Route("plans")]
public ActionResult Plans()
{
var servicePlansDto = SubscriberApiManager.SubscriptionSellingService.GetServicePlans(ServiceId).FindAll(sp => !sp.HasPromotionCode);
List<ServicePlanVm> servicePlansVm = Mapper.Map<List<ServicePlanDto>, List<ServicePlanVm>>(servicePlansDto);
return View(servicePlansVm);
}
下行动,这是我的配置
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
感谢您的答复,我的配置属性航线作为你提到它的第一部分。我没有产品ID要通过,我的行动只是 计划(){}没有任何参数。我尝试过[Route(“plans /”)],但失败了。 –
你会得到什么错误? –
由于URL不正确。 –