I am working with an ASP.NET MVC Application and had problems with some of my calls to the HtmlHelper Extension functions. The following code

Original call to HTML Helper
Original call to HTML Helper

produced the following exception

HTML Helper Exception
HTML Helper Exception

In order to analyze the problem I started with commenting the codeline in question like this

Wrong way to comment code in ASP.NET
Wrong way to comment code in ASP.NET

Well – unfortunately that is not the way to comment source code in your markup file. This markup code gets compiled into the temporary .NET Assembly like this

Generated Code based on Markup Code
Generated Code based on Markup Code

Even though the output of my HtmlHelper call will be under comments in the final HTML – the method is still called – causing the same exception to happen.

To do this right – you have to comment the code within the code block like this

Correct way to comment code in ASP.NET Markup
Correct way to comment code in ASP.NET Markup

Conclusion

Makes sense? Yes – it does. But if you don’t know it you may be surprised about the result.