Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

@: doesn't appear to work #471

Closed
Daniel15 opened this issue Aug 3, 2015 · 7 comments
Closed

@: doesn't appear to work #471

Daniel15 opened this issue Aug 3, 2015 · 7 comments

Comments

@Daniel15
Copy link

Daniel15 commented Aug 3, 2015

http://weblogs.asp.net/scottgu/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax

Not all content container blocks start with a tag element tag, though, and there are scenarios where the Razor parser can’t implicitly detect a content block.

Razor addresses this by enabling you to explicitly indicate the beginning of a line of content by using the @: character sequence within a code block. The @: sequence indicates that the line of content that follows should be treated as a content block

However, ASP.NET MVC 6 is giving me an error when I use it:

":" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.

@NTaylorMullen
Copy link

Are you using it inside of an @{ ... } block?

@Daniel15
Copy link
Author

Daniel15 commented Aug 3, 2015

@NTaylorMullen - This is the exact file I'm using: https://github.com/Daniel15/Website/blob/master/Daniel15.Web/Views/Project/_ProjectList.cshtml#L97-L107

This is the part of the template:

    if (!secondaryTechs.Any())
    {
        return;
    }

    @:+
    foreach (var tech in secondaryTechs)
    {
        if (string.IsNullOrEmpty(tech.Url))
        {
            @:@tech.Name,
        }
        else
        {
            @:<a href="@tech.Url">@tech.Name</a>,
        }
    }

I haven't tried using <text> instead (which should apparently work too)

The live page (which is currently using ASP.NET MVC 4) is here if you want to see how the output currently looks: http://dan.cx/projects

@Daniel15
Copy link
Author

Daniel15 commented Aug 3, 2015

I just realised that Razor may be having problems with that file due to my use of @helper, which was removed in #281. The error messages I got said nothing about @helper though.

@NTaylorMullen
Copy link

Ahh, I see. Looks like the @helper can definitely cause some misleading errors. After removing the @helper do you still see the error?

@Eilon
Copy link
Member

Eilon commented Aug 3, 2015

@NTaylorMullen is @helper still a "reserved word"? If not, then I think it should be, and we should error out on it for now. We'll likely want it back in the future. And that goes for any Razor 3.x feature that is at least temporarily missing - we should have Razor 4.x be aware of it but say it's unsupported.

@NTaylorMullen
Copy link

@Eilon That's a great idea: #472

@Daniel15
Copy link
Author

Daniel15 commented Aug 3, 2015

Looks like it does work; I just tried this which worked as expected:

@if (true) {
        @:foobar
}

Going to close this out since #472 should fix the misleading error messages encountered when this is used inside an @helper block. Thanks!

@Daniel15 Daniel15 closed this as completed Aug 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants