【发布时间】:2019-06-01 21:48:02
【问题描述】:
此代码用于通过RedirectToAction 方法传递List<String>:
public List<String> ListOfBrandNames(string id)
{
var result = db.Items.Where(x => x.Category.Name.Equals(id)).Select(x => x.BrandID).ToList();
var ListOfBrands = db.Brands.Where(t => result.Contains(t.BrandID)).ToList();
List<String> BrandNames = ListOfBrands.Select(f => f.Name.ToString()).ToList();
return RedirectToAction("BrandsOfACategory", new { brands = BrandNames });
}
RedirectToAction 方法抛出此错误:
无法将类型“System.Web.Mvc.RedirectToRootResult”隐式转换为“System.Collection.Generic.List”
【问题讨论】:
-
在您提供的列表中给出了 2 个答案。两者相互确认,所以我实施并检查但在浏览器中出现此错误:
Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /Home/ListOfBrandNames Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0。请删除重复项
标签: c# asp.net-mvc