c# - How to configure route in MVC to pagination list -
i have controller:
public class restaurantcontroller : controller { public actionresult index(string name, int page = 0) { int pagesize = 4; @viewbag.dropcitys = _db.restaurantes.select(c => c.name).distinct(); var model = res in _db.restaurantes orderby res.name descending ( (!string.isnullorempty(name)? res.name.contains(name) : res.name!="") ) select res; return view(model.skip(pagesize * page).take(pagesize).tolist()); }
this route:
routes.maproute( "restaurant", "{controller}/{action}/{page}", new { controller = "restaurant", action = "index", page= urlparameter.optional }, namespaces: new string[] { "mvcintro.controllers" } //usa-se isso para funcionar area );}
i try access page mysite.com/restaurant/1 or mysite.com/restaurant/2
reflect pagination.
i receive error 404
.
i think route incorrect, not know how configure correctly.
thanks.
your route wrong , should more :
routes.maproute( "restaurant", "{name}/{page}", new { controller = "restaurant", action = "index", name= urlparameter.optional page= urlparameter.optional }, namespaces: new string[] { "mvcintro.controllers" } //usa-se isso para funcionar area );
but conflict default route so, more friendly
routes.maproute( "restaurant", // find looks searching reastraunt. "find/{name}/{page}", new { controller = "restaurant", action = "index", name= urlparameter.optional page= urlparameter.optional }, namespaces: new string[] { "mvcintro.controllers" } //usa-se isso para funcionar area );
Comments
Post a Comment