ASP.Net Razor Syntax for using a variable in html or html attribute

Posted by

Because I always forget how to do this, here’s a quick note on the Razor syntax in an html variable. For a integer variable named: imgWidth that has a value of 214 you can put it in an html attribute like this:

and it will render like this:

I know I know. The css gurus will be lambasting me that I put inline styles in this example. So sue me. Sometimes inline styles are necessary.

Leave a Reply

Your email address will not be published. Required fields are marked *