p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET MVC 5 (http://p2p.wrox.com/forumdisplay.php?f=770)
-   -   In MVC 5 (VB) why is the '@' required in front of basic html tags? (http://p2p.wrox.com/showthread.php?t=93481)

AlanWheeler August 29th, 2014 04:43 PM

In MVC 5 (VB) why is the '@' required in front of basic html tags?
 
This code will not work without the @ in front of the <li> tag.

Code:

@For Each A In ViewBag.stuff  (where stuff is a list of strings)
  @<li>@A</li>
Next

Is there an easy rule to remember to know when the @ is required to transition back to html? In the Razor section of Chapter 3 it indicates @ is required to transition from markup to code, and sometimes back, but I never found any examples or explanations about when @ is required for the transition back to markup.

Thanks.

Best Regards,
Alan

AlanWheeler September 2nd, 2014 04:49 PM

Self posted answer
 
From Stack Overflow:

It is required when the previous line is plain code (such as For Each).

This is because in VB there are XML literals that create ambiguity.

aw

JonGalloway September 15th, 2014 04:23 AM

Thanks for posting the update - all the code samples in the book are in C#, and I honestly haven't written much VB.NET for several years (although it was my first .NET language) so I'd have been looking over on SO myself. Of course, seeing the answer makes total sense.


All times are GMT -4. The time now is 08:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.