Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么在HTML.TextArea之前需要一个@?_C#_Html_Asp.net Mvc_Razor - Fatal编程技术网

C# 为什么在HTML.TextArea之前需要一个@?

C# 为什么在HTML.TextArea之前需要一个@?,c#,html,asp.net-mvc,razor,C#,Html,Asp.net Mvc,Razor,除非@在@Html之前,否则下面的内容似乎不起作用。为什么呢 @{ if (DescriptionIsFieldReadOnly) { Html.TextArea("description-edit", Model.Requisition.ReqHdr.Description, new { @Readonly = "readonly" }); }

除非@在@Html之前,否则下面的内容似乎不起作用。为什么呢

@{
 if (DescriptionIsFieldReadOnly) {
                            Html.TextArea("description-edit", Model.Requisition.ReqHdr.Description, new { @Readonly = "readonly" });
                        }
                        else {
                            Html.TextArea("description-edit", Model.Requisition.ReqHdr.Description);
                        } 
}
Html.TextArea(…)
返回包含所需Html代码的
IHtmlString

如果您将其作为一个普通函数调用,那么实际上不会对该返回值执行任何操作,因此不会发生任何事情

使用
@
将其转换为Razor表达式,将其值打印到页面上


顺便说一句,这不是一个语句,因此它不应该有分号。

您可以使用@字符向页面添加代码。 @:序列表示后面的内容行应视为内容块


Html.TextArea返回一个字符串,要使用razor视图引擎进行渲染,如果我返回Html.TextArea(…)而不是@Html.TextArea,您需要在开始时使用@Html.TextArea

。。。它会工作吗?Razor模板不能返回任何内容。它需要一个“=”和一个“@”;没有“@”like,只调用方法,不写入响应