Whats with MVC and sometimes needing a semi colon?

Maybe I’m the only one that was like WTF whenever certain methods required a semicolon and others didn’t within an MVC view, but it was really irritating me. Especially now that Razor adds a new piece requiring the @{ } deal. Not that I mind doing it, it actually separates things out pretty nicely, but I wanted a rhyme or reason for it…. I have when things “just are that way”.

It turns out after finding that Html.RenderPartial() didn’t work by just placing an @ sign in front of it there actually is a logical answer.. sort of.

Apparently, any method that returns void needs a semi colon on the end of the method. In turn anything that requires a semi colon apparently also requires the @{ } combination.

So for example:

ASPX was:

<%: Html.RenderPartial(“MyPartial”); %>

What I thought would be Razor, but was sadly mistaken:

@Html.RenderPartial(“MyPartial”);

The Actual Razor implementation:

@{

Html.RenderPartial(“MyPartial”);

}

Happy Microsoft day 🙂

Advertisements

About Gregg Coleman

I am Senior-level Software Engineer working primarily these days with .NET. I have a good working knowledge of ASP.NET MVC, Web Forms, WCF web services and Windows Services. I spend much of my time in the Web Services (SOAP and REST) world in my current job designing and implementing various SOA architectures. I have been in the software engineering industry for about 6 years now and will not now nor ever consider myself an "expert" in programming because there is always so much to learn. My favorite thing about designing software is there are always new emerging technologies and something to learn every day! My current job has me spending much of my job on the bleeding edge of technologies and changing gears all the time, so I'm never bored and always challenged. On my spare time I enjoy weight training, reading and venturing to new places near by. Of course programing and learning new technologies are another hobby of mine.
This entry was posted in ASP.NET, C#, Computer Technology, MVC and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s