2012-10-30 72 views
0

我有這個宏在運行服務器上快樂地運行。在WebMatrix中可以。現在WebMatrix中完成自我更新2(刷新),它不會運行一些宏,這是其中之一: -Umbraco Razor語法問題

@{ 
    //Check there are slider image page loaded 
    var theCount = @Model.Descendants("SliderImagePage").Count(); 

    if (theCount > 0) 
    { 
     foreach (var theImagePage in Model.Descendants("SliderImagePage")) 
      { 
      var theImage = theImagePage.Media("sliderImage","umbracoFile"); 
      if (theImagePage.IsFirst()) 
      { 
      @:<div class="slide" style="background-image:url('@Html.Raw(theImage)');display:block;"></div> 
      } else { 
      @:<div class="slide" style="background-image:url('@Html.Raw(theImage)');display:none;"></div> 
      } 
      }  
    } 
    else 
    { 
    @: No Picture Image pages set up 
    } 

} 

它抱怨「:」是不是在一個代碼塊的開始有效。

我有MVC4和VS2010中的剃刀擴展。據我瞭解,這一切都是有效的。任何人都可以闡明爲什麼它不會通過驗證?

謝謝。

回答

2

在foreach循環中的陳述不應該使用運行良好@:輸出:

@{ 
    //Check there are slider image page loaded 
    var theCount = @Model.Descendants("SliderImagePage").Count(); 

    if (theCount > 0) 
    { 
     foreach (var theImagePage in Model.Descendants("SliderImagePage")) 
     { 
      var theImage = theImagePage.Media("sliderImage","umbracoFile"); 
      if (theImagePage.IsFirst()) 
      { 
       <div class="slide" style="background-image:url('@Html.Raw(theImage)');display:block;"></div> 
      } 
      else 
      { 
       <div class="slide" style="background-image:url('@Html.Raw(theImage)');display:none;"></div> 
      } 
     }  
    } 
    else 
    { 
     @: No Picture Image pages set up 
    } 
} 
+0

謝謝,刪除他們,但仍VS2010抱怨了@:無圖像的圖像行,以便把它在@ Html.Raw( 「在這裏」);似乎已經過去了。 – Craig

1

看起來你已經發現在剃刀彙編問題。有一個簡單的解決方法;如果你從第3行中刪除'@'字符,那麼你在上面編寫的代碼在Razor v1和Razor v2中編譯。

我在CodePlex的Web頁面團隊的bug數據庫中打開了一個bug,希望它能在下一個版本中解決。

HTH, 克萊

+0

謝謝Clay。你的解決方法允許我修改所有的宏並使它們工作,除了看起來是由於html開始和結束標記超出了範圍,但我不知道該怎麼做: <[email protected] (ulClass)> @foreach(){ 這裏的代碼 } 不能把完整的代碼放在這裏,因爲它太長了。 – Craig

+0

嗨克雷格,爲此,如果您使用:

    @foreach(){code}
- Gareth/agrath – agrath