我正在使用mvc Url.Action作为此
<a href="@Url.Action("Index", "Product", new { area = "Product", search = UrlParameter.Optional, categoryId = category.IdCategory })">
我的路由为: -
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Product_default",
"Product/{controller}/{action}/{id}/{categoryId}",
defaults: new { controller = "Product", action = "Index", search = UrlParameter.Optional, categoryId = @"\d+" },
namespaces: new[] { "IBuyFrontEnd.Areas.Product.Controllers" }
);
}
我无法将网址映射到此路线。我正在把它作为
但是,如果我将操作更改为
@Url.Action("Index", "Product")
我认为这是Url
http://localhost/iteric/?action=Index&controller=Product
我无法弄清楚这种行为的原因。刚开始使用.net mvc。请帮我解决一下这个。
答案 0 :(得分:0)
确定因此,要想让Url.Action生成url,需要在控制器中存在该操作,并且参数应该就位。所以我只是将我的控制器动作改为
public ActionResult Index( int? categoryId,string search)
{
return View();
}