This is a migrated thread and some comments may be shown as answers.

Custom command not finding action

4 Answers 230 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 23 Nov 2016, 04:29 PM

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.}

4 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 25 Nov 2016, 12:39 PM
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.
0
Steve
Top achievements
Rank 1
answered on 25 Nov 2016, 01:22 PM

Hi Kostadin,

 

Thanks for your reply. The URL becomes:

Index/Lockout?CustomerId=190

which doesn't look right

0
Accepted
Mike
Top achievements
Rank 1
answered on 26 Nov 2016, 02:06 PM

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

0
Steve
Top achievements
Rank 1
answered on 28 Nov 2016, 08:30 AM

[quote]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[/quote]

 

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

Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Steve
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Share this question
or