在ASP.NET MVC5中,当使用Url.Action在Razor中生成标签时,如何隐藏Action名称? [英] In ASP.NET MVC5, how can I hide the Action name when an a tag is generated in Razor using Url.Action?
问题描述
正如标题所述.
我设置了一条路由,并且工作正常,当未指定任何路由时,它将提供默认操作.我只想从URL中隐藏操作,因为这是不必要的混乱.
将"ActionName"参数设置为 null
或"
,只会导致替换当前页面的操作-不起作用.>
如果愿意,我愿意使用 @ Html.ActionLink()
.
我的路线定义是
routes.MapRoute(名称:"MyBookRoute",url:"Book/{id}",默认值:new {controller ="Book",action ="Index"});
如果所有其他方法都失败了,我想我可以手动写出hrefs,但这对Razor来说应该不是一件困难的事情.
有没有其他人遇到这个问题并且知道该怎么办?
根据您的路线定义,然后选择
@ Url.Action("Index","Book",新的{id = 1})
或
@ Html.ActionLink(您的链接文本",索引",书",新的{id = 1},null)
将从生成的网址中删除操作名称.
As the title says.
I have a route set up and working fine, which provides a default action when none is specified. I just want to hide the action from the URL because it's unnecessary clutter.
Setting the "ActionName" parameter as null
, or ""
, will just result in the current page's action being substituted instead - which doesn't work.
I'm open to using @Html.ActionLink()
if that will get me what I need.
My route definition is
routes.MapRoute(
name: "MyBookRoute",
url: "Book/{id}",
defaults: new { controller = "Book", action = "Index" }
);
If all else fails, I suppose I can deal with writing out the hrefs manually, but this should not be a difficult thing for Razor to do.
Has anyone else come across this and knows what to do?
Base on your route definition, then either
@Url.Action("Index", "Book", new { id = 1 })
or
@Html.ActionLink("Your link text", "Index", "Book", new { id = 1 }, null)
will remove the action name from the generated url.
这篇关于在ASP.NET MVC5中,当使用Url.Action在Razor中生成标签时,如何隐藏Action名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!