NopCommerce - 搜索框错误

NopCommerce - Error with Search Box

我遇到了这个错误:

The model item passed into the dictionary is of type 
'Nop.Web.Models.Catalog.SearchModel', but this dictionary requires a model 
item of type 'Nop.Web.Models.Catalog.CategoryModel'

完整的错误是这样的:

System.InvalidOperationException: The model item passed into the dictionary 
is of type 'Nop.Web.Models.Catalog.SearchModel', but this dictionary requires 
a model item of type 'Nop.Web.Models.Catalog.CategoryModel'. at 
System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) at 
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) at 
System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData) at 
System.Web.Mvc.WebViewPage.ConfigurePage(WebPageBase parentPage) at 
System.Web.WebPages.WebPageBase.<>c__DisplayClass3. 
<RenderPageCore>b__2(TextWriter writer) at 
System.Web.WebPages.WebPageBase.Write(HelperResult result) at 
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, 
Action`1 body) at System.Web.WebPages.WebPageBase.PopContext() at 
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive 
(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, 
ControllerContext controllerContext, ActionResult actionResult) at 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters 
(ControllerContext controllerContext, IList`1 filters, ActionResult 
actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker. 
<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) at 
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction 
(IAsyncResult asyncResult) at System.Web.Mvc.Controller. 
<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState 
innerState) at 
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate 
(IAsyncResult asyncResult) at 
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at 
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate 
(IAsyncResult asyncResult) at 
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at 
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, 
ProcessRequestState innerState) at 
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate 
(IAsyncResult asyncResult) at 
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at 
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web 
.HttpApplication.IExecutionStep.Execute() at 
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at 
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& 
completedSynchronously)

我修改了 SearchBox.cshtml 以插入我需要父类别 (cid) 和搜索文本 (q) 的输入。所以为了找到我从服务器 SearchBox.cshtml 和 Search.cshtml 删除的错误,但它给了我同样的错误。

我使用的是 nopCommerce 3.90 版

谁能帮我解决这个错误。

您将模型传递给控制器​​查看 - Nop.Web.Models.Catalog.SearchModel 并在视图页面中使用模型 - Nop.Web.Models.Catalog.CategoryModel

在视图页面中使用模型 Nop.Web.Models.Catalog.SearchModel,它将解决您的问题。