【发布时间】:2017-02-17 17:24:05
【问题描述】:
我正在尝试通过以下方式通过辅助方法生成 ActionLink:
return helper.ActionLink(linkText, actionName, controllerName, route, attributes);
我传入的值如下:
new ActionLinkModel
{
LinkText = "Help",
ElementId = "HelpLink",
ActionName = "javascript:void(0);",
ControllerName = "",
HtmlAttributes = new {onclick = "RunSomeFunction(this, 'Something');"}
}
基本上模型会映射到您在我的第一行代码中看到的值。
我在 HTML 页面上得到的输出是这样的:
<a href="/MyWebsite/MyController/javascript%3avoid(0)%3b" id="HelpLink" onclick="RunSomeFunction(this, 'Something');">Help</a>
我希望输出是这样的:
<a href="javascript:void(0);" id="HelpLink" onclick="RunSomeFunction(this, 'Something');">Help</a>
我将如何做到这一点?使用 ActionLink 辅助方法的想法,因为它允许我遍历菜单并将其打印出来,并让菜单成为后端的控制器。
【问题讨论】:
标签: c# asp.net asp.net-mvc razor asp.net-mvc-5