Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Does HTML.TextArea require an @ before it?

The below doesn't seem to work unless @ is before the @Html. Why is that?

@{
 if (DescriptionIsFieldReadOnly) {
                            Html.TextArea("description-edit", Model.Requisition.ReqHdr.Description, new { @Readonly = "readonly" });
                        }
                        else {
                            Html.TextArea("description-edit", Model.Requisition.ReqHdr.Description);
                        } 
}
like image 834
SamIAm Avatar asked Jul 10 '26 19:07

SamIAm


1 Answers

Html.TextArea(...) returns an IHtmlString with the HTML code you want.

If you call it as a normal function, you don't actually do anything with that return value, so nothing happens.

Using @ turns it into a Razor expression that prints its value to the page.

Incidentally, that isn't a statement, so it should not have a semicolon.

like image 179
SLaks Avatar answered Jul 13 '26 11:07

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!