Razor View Engine and jQuery

前端 未结 2 758
一个人的身影
一个人的身影 2020-12-29 10:47

does anybody know how to force Razor View engine to print exact line which is under foreach loop. Code follows :

@section head{


        
相关标签:
2条回答
  • 2020-12-29 11:01

    This very helpful article by Scott Gu explains all you need to know - and has pretty much every situation covered.

    Here's the explicit <text> style mentioned by @Manticore - there's a lot more examples in the article.

    alt text

    0 讨论(0)
  • 2020-12-29 11:21

    Inside the @foreach block, the content is code by default unless you switch back to markup. So the "jQuery(...).progressBar()" line is considered C#. In cases like this, where you want markup that isn't HTML, you can use the <text> tag, which is not actually rendered OR the "@:" directive which instructs Razor to treat the rest of the line as markup, no matter what it contains (of course, you can then use "@" within the line to nest further code blocks).

    Also, the "pb@PlayerID" looks like an email address to Razor so it ignores it. You can avoid that by using the @() explict expression syntax. So the @foreach block should look like this:

    @foreach(var player in Model)
    {
        @: jQuery("#pb@(PlayerID)").progressBar();
    }
    
    0 讨论(0)
提交回复
热议问题