AKD
AKD

Reputation: 3966

C# ASP.NET MVC model binding

in ASP.NET MVC i was trying to bind a model field with displayText with code below:

<%    if (Model.WillAttend == true)
           Html.DisplayTextFor(x => x.Name);   %>

but when i tried:

<%    if (Model.WillAttend == true)     %>  
         <% = Html.DisplayTextFor(x => x.Name)     %>

it is working, why? both seems same code, the only different is in below one is just each line is separated with the server side tag.

Upvotes: 2

Views: 294

Answers (1)

Johny Skovdal
Johny Skovdal

Reputation: 2104

The difference is in the = sign after the open tag <%. This ensures that the value is written to the output. The first example is simply declaring a value and not doing anything with it.

Check out this blog entry for more info on the ASPX view engine tag syntax.

This is simplified a lot with Razor syntax, where you are able to just prefix a line in a codeblock with @ in order to write it to output. I don't know if there is a similar functionality in the ASPX view engine though.

Upvotes: 2

Related Questions