0

I have a two actions like below in restaurant controller

[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);
}

and also i have another two index actions like below

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());
            }

But this gives me an error like this:

The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'System.Collections.Generic.List<RestaurantViewModel>'.

can anyone suggest me a way to achieve this problem ??

Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
siyumi_amarasinghe
  • 193
  • 1
  • 1
  • 13
  • 1
    What part of the error don't you understand? What did your [research](http://stackoverflow.com/questions/23412021/defaultinlineconstraintresolver-error-in-webapi-2) show? What do you expect this constraint to do? – CodeCaster Nov 16 '16 at 13:13
  • Have this method as POST method instead of GET. `[HttpPost][Route("Index}")] public ActionResult Index([FromBody]List restaurants)` – Developer Nov 16 '16 at 13:14

1 Answers1

1

The problem is in your route:

[Route("Index/{restaurants:System.Collections.Generic.List<RestaurantViewModel>}")] 

Try with :

[Route("Index/{restaurants}")] 

You have a list of the DefaultInlineConstraintResolver here : DefaultInlineConstraintResolver Error in WebAPI 2

Community
  • 1
  • 1
Yanga
  • 2,885
  • 1
  • 29
  • 32
  • I modified the code please can anyone give me a solution to according to that? – siyumi_amarasinghe Nov 16 '16 at 15:01
  • Do you have any error message when you try to post to your searchOpenRestaurants Action ? Do you still have "The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'System.Collections.Generic.List'." ? – Yanga Nov 16 '16 at 15:21