html"id";在actionLink剃刀助手中 [英] html "id" in actionLink razor helper

查看:66
本文介绍了html"id";在actionLink剃刀助手中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ActionLink中指定html id,但是我不能这样做:

I want to specify the html id in ActionLink, but I can't do this:

@html.ActionLink("Controller", "Action", new {@id = "tec"})

因为@id表示tecid参数的值.

另一方面,如果我愿意

@html.ActionLink("Controller", "Action", new {@class = "tec"})

结果将是:

<a href="Controller/Action" class="tec"></a>

您知道一种指定html ID的方法吗?

Do you know a way to specify the html id?

我想要这个结果:

<a href="Controller/Action" id="tec"></a>

推荐答案

您还必须指定控制器,并且可以在id之前删除@

You have to specifiy also the controller and you can remove the @ before id

@Html.ActionLink("mylink", "Action", "Controller", new {id = "tec"})

这是因为您使用的签名不是与HtmlAttributes相关的签名,而是与路由值相关的签名.如果您不想指定控制器,请使用此

That's because the signature you are using is not the one relative to HtmlAttributes, but to the routing values. If you do not want to specify the controller, use this

@Html.ActionLink("mylink", "Action", null, new {id = "tec"})

这篇关于html"id";在actionLink剃刀助手中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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