Double fermentation lane

How do I avoid the colon in my shaving code?

That's my problem:

@ count@ :: @item.Title - @item.Link - @item.Price 

Which causes an error after the @count variable. How can I use a colon next to my counter?

It should look like this:

 1: Title - Link - Price 

** UPDATE **

My code block

 @{ int count = 0; foreach (var item in Model.Wishes) { count++; @ count@ :: @item.Title - @item.Link - @item.Price <br /> } } 
+6
source share
2 answers

You need to wrap the display part of your code in <text> tags. The colon should not be avoided.

 @{ int count = 0; foreach (var item in Model.Wishes) { count++; <text> @count: @item.Title - @item.Link - @item.Price <br /> </text> } } 

http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx

The <text> is an element specially crafted by Razor. This leads to the fact that Razor interprets the internal content of the <text> block as content and does not display the contained element of the <text> (which means that only the internal content of the <text> element will be displayed - the tag itself will not be), This makes it convenient if you want to display multi-line blocks of content that are not wrapped by an HTML element.

http://www.asp.net/web-pages/tutorials/basics/2-introduction-to-asp-net-web-programming-using-the-razor-syntax#BM_CombiningTextMarkupAndCode

Use the @: operator or the <text> element. @: prints a single line of content containing plain text or inconsistent HTML tags; the <text> element contains several lines for output. These options are useful when you do not want to display an HTML element as part of the output.

+10
source

If count is declared as a variable, this should work.

 @{ var count = 4; } @count: 

If the counter is part of your model, then this should work.

 @model MvcApplication4.Models.DemoViewModel @{ ViewBag.Title = "Index"; } <h2>Index</h2> @Model.Count: 
0
source

All Articles