Monday, May 27, 2013

Code Nuggets

              Code nuggets are simple expressions that are evaluated and rendered inline. They can be mixed with text and look like this:

                         Not Logged In: @Html.ActionLink("Login", "Login")

              The expression begins immediately after the @ symbol, and Razor is smart enough to know that the closing parenthesis indicates the end of this particular statement. The previous example will render this output:        
                     
                        Not Logged In: <a href="/Login">Login</a>

              Notice that code nuggets must always return markup for the view to render. If you write a code nugget that does not return anything (i.e. returns void), you will receive an error when the view executes.

No comments:

Post a Comment