ASP.NET MVC:在C#code座使用@NET、ASP、code、MVC

2023-09-06 17:50:01 作者:一身可爱味儿

我是有点困惑与使用@。在下面的code我第一次写 Html.ActionLink(...),而不是 @ Html.ActionLink(...),因为我是在一个如果块(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 ,@ {...}等))

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.