Prakash Chandra
Prakash Chandra

Reputation: 317

syntatical difference b/w <%= Html.LabelFor(model=> model.studFatherName) %> and <%: Html.LabelFor(model=> model.studFatherName) %>

i am bit confuse in the syntax used in mvc. please tell me what is difference between these two syntax written below :
<%= Html.LabelFor(model=> model.studFatherName) %> and
<%: Html.LabelFor(model=> model.studFatherName) %>

Upvotes: 0

Views: 297

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

<%: %> is used to HTML encode the value whereas <%= %> output the value as is. For example:

<%= "<br/>" %> is rendered as <br/> whereas <%: %> is rendered as &lt;br/&gt;. There is one exception though. If the argument is an IHtmlString then <%: %> behaves exactly the same as <%= %> i.e. it doesn't encode the value. And since the LabelFor helper returns an IHtmlString <%: Html.LabelFor(x => x.studFatherName) %> is absolutely equivalent to <%= Html.LabelFor(x => x.studFatherName) %>.

Upvotes: 2

Related Questions