& # 39; System.Collections.Generic.List<祝辞& # 39;路由属性
本文关键字:祝辞 路由 lt 属性 Collections System Generic List | 更新日期: 2023-09-27 18:18:06
我在餐厅控制器中有两个动作,如下所示
[HttpPost]
public ActionResult searchOpenRestaurants(FormCollection form)
{
TimeSpan currentTime = DateTime.Now.TimeOfDay;
var openRestaurants = (from t in db.Restaurants
where
t.OpeningTime == currentTime ||
t.OpeningTime < currentTime ||
t.ClosingTime > currentTime ||
t.ClosingTime == currentTime
select new RestaurantViewModel()
{
RestId = t.Id,
RestaurantName = t.RestaurantName,
Logo = t.Logo,
Address = t.Address,
City = t.City,
District = t.District,
TimetakentoDeliver = t.TimetakentoDeliver,
categories = t.Restaurant_Type.Select(a => a.Category.category1).ToList(),
}).ToList();
return View("Index", openRestaurants.ToList());
}
[Route("Index/{restaurants:System.Collections.Generic.List<RestaurantViewModel>}")]
public ActionResult Index(List<RestaurantViewModel> restaurants)
{
return View(restaurants);
}
还有两个索引动作比如
下面public ActionResult Index()
{
using (TheFoodyContext db = new TheFoodyContext())
{
var model = (from p in db.Restaurants // .Includes("Addresses") here?
select new RestaurantViewModel()
{
RestId = p.Id,
RestaurantName = p.RestaurantName,
Logo = p.Logo,
Address = p.Address,
City = p.City,
District = p.District,
TimetakentoDeliver = p.TimetakentoDeliver,
categories = p.Restaurant_Type.Select(a => a.Category.category1).ToList(),
});
return View(model.ToList());
//return View(db.Restaurants.ToList());
}
}
[HttpPost]
[Route("Index/{search:string}")]
// GET: Restaurant
public ActionResult Index(string search)
{
using (TheFoodyContext db = new TheFoodyContext())
{
var model = (from p in db.Restaurants // .Includes("Addresses") here?
where p.City.StartsWith(search) || search == null
select new RestaurantViewModel()
{
RestId = p.Id,
RestaurantName = p.RestaurantName,
Logo = p.Logo,
Address = p.Address,
City = p.City,
District = p.District,
TimetakentoDeliver = p.TimetakentoDeliver,
categories = p.Restaurant_Type.Select(a => a.Category.category1).ToList(),
});
return View(model.ToList());
//return View(db.Restaurants.ToList());
}
但是这会给我一个这样的错误:
谁能给我一个解决这个问题的方法?类型为'DefaultInlineConstraintResolver'的内联约束解析器无法解析以下内联约束:'System.Collections.Generic.List
'.
问题出在你的路由上:
[Route("Index/{restaurants:System.Collections.Generic.List<RestaurantViewModel>}")]
Try:
[Route("Index/{restaurants}")]
你有一个DefaultInlineConstraintResolver的列表:WebAPI 2中的DefaultInlineConstraintResolver错误