如何在 Razor 中的 ActionLinks 上指定 css 类名? [英] How can you specify a css class name on ActionLinks in Razor?

查看:52
本文介绍了如何在 Razor 中的 ActionLinks 上指定 css 类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码产生错误:

@Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" });

我尝试使用 @ 因为 class 是一个关键字.用剃刀的时候应该怎么写?

I tried to use @ since class is a keyword. How should I write it when using razor?

编辑

问题不是真正的 at 符号,而是我没有将块与 if 一起使用:

The problem was not really the at sign, but that I didn't use blocks together with my if:

@if (blabla)
    @Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" });

作品:

@if (blabla)
{
    @Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" });
}

对这两个答案都投了赞成票,因为他们让我意识到了这个问题.

Up voted both answers since they made me realize the problem.

推荐答案

尝试写一些类似的东西:

Try to write something like:

@(Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" }));

有一篇关于 Razor 的好帖子与您的问题相关:ScottGu博客

There is a good post about Razor related to your problem: ScottGu Blog

这篇关于如何在 Razor 中的 ActionLinks 上指定 css 类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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