ASP.NET MVC:在C#code座使用@ [英] ASP.NET MVC: use of @ in C# code block
问题描述
我是有点困惑与使用@。在下面的code我第一次写 Html.ActionLink(...)
,而不是 @ Html.ActionLink(...)对code>,因为我是在一个
如果
块(C#code)。所以,我想确切地了解什么时候我必须使用@当我不都使用它。
I'm a little bit confused with the use of @. In the following code I first wrote Html.ActionLink(...)
instead of @Html.ActionLink(...)
because I was in a if
block (C# code). So, I would like to understand exactly when I do have to use @ and when I don´t have to use it.
<td width="32%" align="center">
@if (Model.SeccionImpresos != null)
{
@Html.ActionLink("IMPRESOS", "Index", "Trabajo", null, null, "#impresos", new { id = Model.Id }, null);
}
</td>
我AP preaciate有这方面的帮助。
I appreaciate any help on this.
推荐答案
@
有两种用途:
-
它用于启动code的块的(
@if
,@foreach 从标记方面(从另一个code座反对code>,@ {...}等))
It's used to start a code block (
@if
,@foreach
, @{ ... }, etc) from a markup context (as opposed to from another code block)
它用于code的掘金的&ndash的;这是写入到输出流EX pressions( @ EX pression
)。
It's used for code nuggets – expressions which are written to the output stream (@expression
).
写 Html.ActionLink
没有 @
在code块创建正常的方法调用放弃其的结果。
Writing Html.ActionLink
without @
in a code block creates a normal method call that discards its result.
这篇关于ASP.NET MVC:在C#code座使用@的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!