【发布时间】:2020-07-06 08:44:54
【问题描述】:
所以我有一个我试图传递给另一条路线的对象。
在我的 index.cshtml 中,我正在创建要发送的字典对象:
@{
var data = new Dictionary<string , ProductToCart>
{
{"item", Model }
};
}
我也有链接标签(在这个视图中)与 asp-all-route-data 以将我的字典传递给如下:
<a asp-controller="Cart" asp-action="AddToCart" asp-route="productData" asp-all-route-data="data" class="btn btn-lg btn-outline-primary text-uppercase"> <i class="fas fa-shopping-cart"></i> Add to cart </a>
我收到以下错误:
错误 CS0266 无法隐式转换类型 'System.Collections.Generic.Dictionary
' 到 'System.Collections.Generic.IDictionary '。明确的 存在转换(您是否缺少演员表?)
问:如何转换这个字典,它是在 ASP.NET CORE MVC 中通过路由传递字典/复杂对象的正确方法?
【问题讨论】:
-
嗨@Shaz,有关此案的任何更新?您是否使用我们共享的解决方案解决了问题?
标签: c# asp.net dictionary asp.net-core .net-core