2010-07-09 52 views
0

我一直在下面史蒂芬·桑德森的書叫臨ASP.NET MVC框架,和我運行到一個例外:MVC SportsStore:建立一個分類導航菜單]

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0121: The call is ambiguous between the following methods or properties: 'Microsoft.Web.Mvc.ViewExtensions.RenderAction(System.Web.Mvc.HtmlHelper, string, string)' and 'System.Web.Mvc.Html.ChildActionExtensions.RenderAction(System.Web.Mvc.HtmlHelper, string, string)'

Line 15:  </div> 
Line 16:  <div id="catagories"> 
Line 17:   <% Html.RenderAction("Menu", "Nav"); %> 
Line 18:  </div> 
Line 19:  <div id="content"> 

我的網站。主代碼:

<body> 
    <div id="header"> 
     <div class="title"> 
      SPORT STORE</div> 
    </div> 
    <div id="catagories"> 
     <% Html.RenderAction("Menu", "Nav"); %> 
    </div> 
    <div id="content"> 
     <asp:ContentPlaceHolder ID="MainContent" runat="server" /> 
    </div> 
</body> 

我感謝我知道哪裏出錯了。當我將MVC1的Microsoft.Web.Mvc.dll更改爲MVC2的Microsoft.Web.Mvc.dll時,此錯誤已解決。但它出現其他錯誤:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0234: The type or namespace name 'NavLink' does not exist in the namespace 'WebUI.Controllers' (are you missing an assembly reference?)

源錯誤:

Line 170:  
Line 171: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()] 
Line 172: public class views_nav_menu_ascx : System.Web.Mvc.ViewUserControl<IEnumerable<WebUI.Controllers.NavLink>> { 
Line 173:   
Line 174:  private static bool @__initialized; 

所以,我該怎麼辦?

回答

1

在第5章,137頁:

<%@ Control Language="C#" 
Inherits="System.Web.Mvc.ViewUserControl 
<IEnumerable<WebUI.Controllers.NavLink>>" %> 

並沒有爲我工作。我一直得到:名稱空間'WebUI.Controllers'中不存在類型或命名空間名稱'NavLink'

我必須將「... Controllers.NavLink ...」更改爲「... Controllers.NavController .NavLink ...「以便它工作。像這樣:

<%@ Control Language="C#" 
Inherits="System.Web.Mvc.ViewUserControl 
<IEnumerable<WebUI.Controllers.NavController.NavLink>>" %>