为了避免在自动生成的ActionLink的查询字符串值 [英] To avoid auto generated Query string value in ActionLink

查看:133
本文介绍了为了避免在自动生成的ActionLink的查询字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是想添加一个CSS类锚定,但同时呈现的HTML href属性有查询字符串值4.控制器名称家的长度被追加到HREF链接。如果我删除的CSS类它的正常工作。何来避免自动生成的查询字符串值。

剃须刀code:

  @ Html.ActionLink(创建应用程序,CreateApplication,家,新的{@类=链接});

呈现的HTML是:

 < A HREF =?/帐号/ CreateApplication长度= 4级=链接>创建应用程序和LT; / A>


解决方案

如果你想通过控制器名称,你可以使用下面的签名参数:

 公共静态MvcHtmlString的ActionLink(
    这个的HtmlHelper的HtmlHelper,
    串LINKTEXT,
    串actionName,
    串controllerName,
    对象routeValues​​,
    对象htmlAttributes

所以,你应该用这样的:

  @ Html.ActionLink(创建应用程序,CreateApplication,家,空,新的{@class =链接});

I was trying to add a css class to anchor but while rendering to html the href attribute has query string with value 4. The controller name "Home" length is appended to href link. If I remove the css class it's working fine. Ho to avoid the autogenerated query string value.

Razor Code:

@Html.ActionLink("Create Application", "CreateApplication", "Home", new {@class="link"});

Rendered html is :

<a href="/Account/CreateApplication?Length=4" class="link">Create Application</a>

解决方案

If you want to pass the controller name as a parameter you can use the following signature:

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    Object routeValues,
    Object htmlAttributes
)

So, you should use it like this:

@Html.ActionLink("Create Application", "CreateApplication", "Home", null, new { @class = "link" });

这篇关于为了避免在自动生成的ActionLink的查询字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆