Liz*_*Liz 5 c# urlhelper asp.net-mvc-2
我试图创建一个链接Url.Action,其中有结束#something ; 我认为路线值中有一些东西可以正确地做到这一点,但我找不到谷歌.
到目前为止,我试过了Url.Action("action", "controller", new {id="something", Area="area"}).结果链接是预期/动作/控制器/区域,但我最终无法解决#something问题.
亲戚,我可能会说<a href="<%= Url.Action(..)
%>#something">but但这并没有让我觉得特别好; 我正在寻找更好的解决方案.
Mat*_*son 13
该方法没有超载Url.Action()为您执行此操作.以太,您必须按照建议的方式(通过在调用后简单地添加它Url.Action())或创建自己的扩展方法.
您的扩展方法可能如下所示:
public static MvcHtmlString Action(this UrlHelper urlHelper, string action, string controller, string hash)
{
return string.Format("{0}#{1}", urlHelper.Action(action, controller), hash);
}
Run Code Online (Sandbox Code Playgroud)