Url.Action 路由参数未按预期呈现
Url.Action route parameters not rendered as expected
我在构建 url 重定向时遇到了问题,该重定向是从模型中获取的值传递到我的 MVC 应用程序中的 Razor 视图。
锚标记的 href 属性如下所示(foreach 循环生成的标记列表):
@Url.Action(item.Action, item.Controller, new RouteValueDictionary(new { parameter= item.ActionParameter }
控制器具有由属性定义的路由:
[RoutePrefix("SampleController")]
public class ChartController : Controller
{
[Route("MyActionName/{parameter}")]
public ActionResult SampleAction(string parameter) {}
}
呈现的 url 将参数作为查询参数传递:?parameter=value。如何更改它以实现类似:/SampleController/MyActionName/ParameterValue??
我会很感激你的帮助
此致,
亚采克
试试这个语法
@Url.Action(item.Action, item.Controller, new { id= item.ActionParameter })
我在构建 url 重定向时遇到了问题,该重定向是从模型中获取的值传递到我的 MVC 应用程序中的 Razor 视图。
锚标记的 href 属性如下所示(foreach 循环生成的标记列表):
@Url.Action(item.Action, item.Controller, new RouteValueDictionary(new { parameter= item.ActionParameter }
控制器具有由属性定义的路由:
[RoutePrefix("SampleController")]
public class ChartController : Controller
{
[Route("MyActionName/{parameter}")]
public ActionResult SampleAction(string parameter) {}
}
呈现的 url 将参数作为查询参数传递:?parameter=value。如何更改它以实现类似:/SampleController/MyActionName/ParameterValue??
我会很感激你的帮助
此致, 亚采克
试试这个语法
@Url.Action(item.Action, item.Controller, new { id= item.ActionParameter })