2011-10-25 48 views
6

我碰到在Visual Studio 2010與HTML5驗證這種奇怪的驗證錯誤選擇:Visual Studio的HTML5驗證:元素 'IMG' 不能嵌套元素中的 'A'

Validation error

這是一個驗證錯誤(合法或Visual Studio中的錯誤)還是我錯過了一些明顯而簡單的東西?


編輯:添加相關的代碼。

查看cshtml

@model My.Web.ViewModels.ListVideos 

@{ 
    ViewBag.Title = "All Videos"; 
} 

@foreach (var item in Model.Videos) { 
    <a href="@Url.Action("Play", "Player", new { videoId = item.VideoId })"> 
     <img src="http://i2.ytimg.com/vi/@item.PublisherVideoId/default.jpg" alt="@item.Title" style="border: 0" /> 
    </a> 
} 

_Layout.cshtml

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <title>@ViewBag.Title</title> 
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> 
    <script src="@Url.Content("~/Scripts/jquery-1.6.4.min.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script> 
</head> 
<body> 
    <div class="page"> 
     <header> 
      <div id="title"> 
       <h1>My Web</h1> 
      </div> 
      <div id="logindisplay"> 
       @Html.Partial("_LogOnPartial") 
      </div> 
      <nav> 
       <ul id="menu"> 
        <li>@Html.ActionLink("Videos", "ListVideos", "Player")</li> 
        <li>@Html.ActionLink("Dev", "Index", "Dev")</li> 
       </ul> 
      </nav> 
     </header> 
     <section id="main"> 
      @RenderBody() 
     </section> 
     <footer> 
     </footer> 
    </div> 
</body> 
</html> 
+0

除了截圖之外,還可以粘貼HTML的整個相關塊嗎? – ObscureRobot

+0

我的代碼很簡單,並且使用默認的MVC3 web應用程序模板,但是我已經將它包含在內了。 –

回答

11

您需要的Visual Studio 2010 SP1的Web標準更新正確有這個工作。這是一個錯誤。

查看更多在這裏:http://blogs.msdn.com/b/webdevtools/archive/2011/06/15/web-standards-update-for-visual-studio-2010-sp1.aspx?PageIndex=2

獲取Web標準更新在這裏: http://visualstudiogallery.msdn.microsoft.com/a15c3ce9-f58f-42b7-8668-53f6cdc2cd83

+0

我有SP1:'版本10.0.40219.1 SP1Rel' –

+0

查看我的更新回答 –

+0

就是這樣,Web標準更新工作。謝謝!在那個筆記上,如果有一種簡單的方法來跨計算機同步更新(或者看到這樣的通知),那將會很不錯。我的桌面有更新,但我的筆記本沒有。 –

2

如果檢查W3C documentation關於HTML5,你會發現,你可以有一個a標籤什麼裏面,如果它不是按鈕或其他鏈接。

只要內部沒有交互式內容(例如按鈕或其他鏈接),a元素可能會纏繞在整個段落,列表,表格等等甚至整個區段中。