2014-07-25 85 views
1

我將MvcSiteMapProvider MVC 4升級到MVC 5後出現問題。 我爲我的視圖使用了一個自定義的「pageBaseType」,而且似乎MvcSiteMapProvider MVC 5確實不允許這樣做? 我不斷收到錯誤:MvcSiteMapProvider MVC 5自定義ViewBase?

The view at '~/Views/Shared/DisplayTemplates/SiteMapPathHelperModel.cshtml' must derive from WebViewPage, or WebViewPage<TModel>. 

在@ Html.MvcSiteMap()的SiteMapPath()。

但是,我的自定義視圖繼承了System.Web.Mvc.WebViewPage。 我在這裏錯過了什麼嗎?

如果我刪除了行@ Html.MvcSiteMap()。SiteMapPath(),頁面工作正常,但沒有sitemappath,當然。

在此先感謝您的幫助!

+0

什麼樣的MVC 5的構建,你看到這與? – NightOwl888

+0

我使用最新的一個可用通過nuget:版本:4.6.10 – hawl

+0

不,不是MvcSiteMapProvider構建,MVC 5構建。這是5.1嗎? – NightOwl888

回答

0

我試圖重現您的問題,但我沒有得到相同的錯誤。您可以使用Here is the project來嘗試解決您的問題。

如果您的項目中有擴展名爲.aspx的文件,它會導致NuGet包將網頁模板(不是剃鬚刀)安裝到/Views/Shared/DisplayTemplates/目錄中的項目中。檢查該目錄以確保所有文件都具有.cshtml擴展名。

如果不是,您可以從here獲取最新版本的.cshtml模板。或者,您可以將其複製出項目中的\packages\MvcSiteMapProvider.Web.[installed version]\content\Views\Shared\DisplayTemplates\文件夾。

+0

非常感謝,我會給它一試! – hawl

+0

在我的情況 - 這是在web.config中創建問題的人:(它有5.0而不是正確的5.1)我正在使用mvc5。 - –

0

好了,現在我想通了,少了什麼: 我沒有具體的組件在我的web.config結合:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 

我看到這個在你們提供的項目並將其添加我的配置。 ..瞧,它現在正在工作。 謝謝你的幫助!

0

我遇到了同樣的問題。 我用以下簡單的web.config,@ Html.MvcSiteMap()測試了一個簡單的Test視圖,SiteMapPath()工作正常。

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=301880 
    --> 
<configuration> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="PreserveLoginUrl" value="true" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 

    <add key="MvcSiteMapProvider_UseExternalDIContainer" value="false" /> 
    <add key="MvcSiteMapProvider_IncludeAssembliesForScan" value="Fairfax.Classifieds.Drive.WebMVC" /> 
    <add key="MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" value="true" /> 
    <add key="MvcSiteMapProvider_EnableSiteMapFile" value="false" /> 
    <add key="MvcSiteMapProvider_IncludeRootNodeFromSiteMapFile" value="true" /> 

    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <pages> 
     <namespaces> 
     <add namespace="MvcSiteMapProvider.Web.Html" /> 
     <add namespace="MvcSiteMapProvider.Web.Html.Models" /> 
     </namespaces> 
    </pages> 
    </system.web> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 

</configuration> 

但我的web.config更復雜。我遇到堆棧跟蹤錯誤:

'〜/ Views/Shared/DisplayTemplates/SiteMapPathHelperModel.cshtml'中的視圖必須來自WebViewPage或WebViewPage。

[InvalidOperationException: The view at '~/Views/Shared/DisplayTemplates/SiteMapPathHelperModel.cshtml' must derive from WebViewPage, or WebViewPage<TModel>.] 
    System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +401 
    System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107 
    System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions) +544 
    System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1089 
    System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData) +66 
    System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData, TemplateHelperDelegate templateHelper) +119 
    System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData) +104 
    MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String templateName, ISiteMapNode startingNode, SourceMetadataDictionary sourceMetadata) +232 
    MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String templateName, String startingNodeKey, SourceMetadataDictionary sourceMetadata) +70 
    MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper) +45 
    ASP._Page_Views_Home_Test_cshtml.Execute() in c:\Projects\Drive\drive\Src\Web\Views\Home\Test.cshtml:9 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198 
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104 
    System.Web.WebPages.StartPage.RunPage() +17 
    System.Web.WebPages.StartPage.ExecutePageHierarchy() +64 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78 
    System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256 
    System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107 
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52 
    System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173 
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39 
    System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29 
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9657896 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 

我把破發點,在@ Html.MvcSiteMap()的SiteMapPath(),在監視窗口@ Html.MvcSiteMap()引發異常

@Html.MvcSiteMap() 'System.Web.Mvc.HtmlHelper<object>' does not contain a definition for 'MvcSiteMap' and the best extension method overload 'MvcSiteMapProvider.Web.Html.HtmlHelperExtensions.MvcSiteMap(System.Web.Mvc.HtmlHelper)' has some invalid arguments 

你能告訴我哪個區域導致錯誤的風險最大?