Custom command not finding action

5 posts, 2 answers
  1. Steve
    Steve avatar
    3 posts
    Member since:
    Nov 2016

    Posted 23 Nov 2016 Link to this post

    Hi,

    I'm trying to implement a custom command on my grid, which is using server binding, but the button just leads to a 'resource not found' error. My routing looks as it should and I can't see anything else wrong. I should also say that the MVC stuff is actually implemented in an 'area'. All my code is below, could anyone help?

    Routing

    1.context.MapRoute(
    2.   "ControlPanel_default",
    3.   "ControlPanel/{controller}/{action}/{id}",
    4.   new { action = "Index", id = UrlParameter.Optional }
    5.);

    Index.cshtml

    01.@(Html.Kendo().Grid(Model)
    02.    .Name("Grid")
    03.    .Columns(col =>
    04.    {
    05.        col.Bound(p => p.CustomerId);
    06.        col.Bound(p => p.aspNetUserID);
    07.        col.Command(cmd =>
    08.        {
    09.            cmd.Edit();
    10.            cmd.Custom("Test").Action("Lockout", "Index");
    11.        });
    12.    })
    13.    .Editable(edt => edt.Mode(GridEditMode.PopUp))
    14.    .Pageable()
    15.    .Sortable()
    16.    .Scrollable()
    17.    .DataSource(ds => ds
    18.    .Server()
    19.    .Model(mdl => mdl.Id(p => p.CustomerId))
    20.    .Read("Index","Index")
    21.    .Update("Update","Index")
    22.    .Create("Create","Index")
    23.    .Destroy("Destroy","Index"))
    24.    )

     

    IndexController.cs

    01.public class IndexController : Controller
    02.{
    03.   public ActionResult Index()
    04.   {
    05.      ViewBag.Title = "Home";
    06.      return View(GetCustomers());
    07.   }
    08.   public ActionResult Lockout(int CustomerId)
    09.   {
    10.      if (ModelState.IsValid)
    11.      {
    12.         //var result = CustomerId;
    13.         RouteValueDictionary routeValues = this.GridRouteValues();
    14.         return RedirectToAction("Index", routeValues);
    15.      }
    16.      return View("Index");
    17.   }
    18.}
  2. Answer
    Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 25 Nov 2016 Link to this post

    Hello Steve,

    Could you please check the url after redirecting to the view? Could you please verify that is the correct one? Keep in mind that the Action method accept a third argument which is the route values, so you might need to set it in your case.  

    I am looking forward to your reply.

    Regards,
    Kostadin
    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
  3. Steve
    Steve avatar
    3 posts
    Member since:
    Nov 2016

    Posted 25 Nov 2016 in reply to Kostadin Link to this post

    Hi Kostadin,

     

    Thanks for your reply. The URL becomes:

    Index/Lockout?CustomerId=190

    which doesn't look right

  4. Answer
    Mike
    Mike avatar
    9 posts
    Member since:
    Apr 2011

    Posted 26 Nov 2016 in reply to Steve Link to this post

    Hi Steve,

    Have you tried Kostadin's proposal about the 3rd parameter in the Action method? Since you're using routes you'll need to specify the 'Area' in the 3rd parameter. Like so: .Action("actionName", "controllerName", new { Area = "areaName" });

    -Mike

  5. Steve
    Steve avatar
    3 posts
    Member since:
    Nov 2016

    Posted 28 Nov 2016 Link to this post

    Hi Steve,
    Have you tried Kostadin's proposal about the 3rd parameter in the Action method? Since you're using routes you'll need to specify the 'Area' in the 3rd parameter. Like so: .Action("actionName", "controllerName", new { Area = "areaName" });
    -Mike

     

    Hi Mike,

    I've tried this and it works as expected now, though the URL format is not what i'd expect from the routing. Would you expect a query string style URL?

    Thanks for all your help guys

Back to Top