Attribut Ich habe eine zwei Aktionen wie unten im Restaurant Controller'System.Collections.Generic.List <>' in Route
[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);
}
und ich habe auch noch zwei Indices Aktionen wie unter
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());
}
Aber das gibt mir einen Fehler wie folgt aus:
Die Inline-Constraint-Resolver des Typs ‚DefaultInlineConstraintResolver‘ war nicht in der Lage zu lösen die folgende Inline-Einschränkung: 'System.Collections.Generic.List <RestaurantViewModel>'.
kann mir jemand einen Weg vorschlagen, dieses Problem zu erreichen ??
Welcher Teil des Fehlers nicht Du verstehst? Was hat Ihr [Forschung] (http://stackoverflow.com/questions/23412021/defaultinlineconstraintresolver-error-in-webapi-2) gezeigt? Was erwarten Sie von dieser Einschränkung? – CodeCaster
Haben Sie diese Methode als POST-Methode anstelle von GET. '[HttpPost] [Route (" Index} ")] öffentlicher ActionResult Index ([FromBody] Liste Restaurants)' –
Developer