c# - 传入 ViewDataDictionary 的模型项在 nopcommerce 4.2 中属于“Castle.Proxies.Model”类型
问题描述
当我将数据传递给模型并调用视图时,这个错误会抛出我。
这是完整的错误显示,
处理请求时发生未处理的异常。InvalidOperationException:传递到 ViewDataDictionary 的模型项的类型为“Castle.Proxies.VendorProxy”,但此 ViewDataDictionary 实例需要类型为“System.Collections.Generic.IList`1[Nop.Web.Models.Common.VendorDetailModel”的模型项]'。
现在,我在 nopcommerce 4.2 中创建了一个模型、一个视图和一个控制器。
这里是我的模范地方,
Nop.Web => 模型 => 通用 => VendorDetailModel
这是模式的代码
public VendorDetailModel()
{
Address = new List<AddressModel>();
}
public string Name { get; set; }
public IList<AddressModel> Address { get; set; }
这是放置的控制器
Nop.Web => Controllers => CommonController => Vendordetail(method)
这是控制器代码
public virtual IActionResult Vendordetail(int vendorId)
{
var model = _vendorService.GetVendorById(vendorId);
return View("Vendordetail",model);
}
这是放置的视图,
Nop.Web => Views => Common => Vendordetail.cshtml
这是查看代码
@model VendorDetailModel
content.......
因此,当我将@model VendorDetailModel放在视图文件中时会显示此错误,而如果我删除此行则不会显示错误。但是我删除了这条线,那么我如何在没有模型的情况下获得价值。
解决方案
也许在您看来,您将错误的模型传递给局部视图。就我而言,我的视图正在获取“BOX”的模型,并使用期望“ORDER”模型的局部视图,但我没有明确地将“ORDER”模型传递给局部,因此局部视图得到了默认的“BOX”模型,这是错误的并触发了这个“Castle.model.proxy”错误。
推荐阅读
- vuejs2 - 无法从使用 npm 安装的包中访问功能
- java - Android GPU渲染速度慢的问题
- survey - 使用 Svyciprop 获得两个变量的 CI 流行率
- javascript - 如何将第一个 API 调用的返回值用作第二个 API 调用的参数?
- javascript - Bookshelf.js:避免调用保存(更新)后的获取调用
- macos - 沙盒 Mac 应用程序和插件之间的进程间通信
- dpdk - DPDK 中的 MultiQ 是配置“max_rx_queue=1”问题
- javascript - 无法在服务端使用 Spring Boot 设置 cookie
- node.js - 在云函数中进行多个 Firestore 查询
- javascript - 在角度的ngx-mat-datetime-picker中设置默认分钟?