Kendo UI JQuery for MVC Web App, can't call a Server-Side Method

1 Answer 131 Views
General Discussions
Walter
Top achievements
Rank 2
Iron
Walter asked on 16 May 2024, 04:47 PM

In my MVC Kendo-Grid web app, I need to periodically see if certain data in the underlying database has expired. If it has, then I modify the data in the database and the normal "refresh" cycle of the Grid updates the displayed data. So, here is my server-side method, contained in my GridController.cs (from the "Controller" part of MVC), abridged:

namespace WireDashboard2.Controllers
{
    public partial class GridController : Controller
    {

....

        [System.Web.Services.WebMethod]
        public static void ReviewSuspensions()
        {
            ... do some database stuff ....
        }

....

}

And here is the client-side JavaScript method that is supposed to be calling GridController.ReviewSuspensions() method:

    function Check4ExpiredSuspensions() {
        $.ajax({
            url: '@Url.Action("GridController", "ReviewSuspensions")',
            success: function() {
                    alert("Reviewed Suspensions successfully!");
            },
            error: function() {
                    alert('Did NOT review Suspensions successfully.');
            }
        }); // GET http://localhost:63794/GridController/ReviewSuspensions 404 (Not Found)
    }

I know the "Check4ExpiredSuspensions() JavaScript is being called on the client-side, because it is attempting to invoke the method, resulting in a 404 (Not Found) error being returned. That JavaScript function is from the WireDashbard2\Views\Home\Index.cshtml file (the "View" part of MVC).

I've tried literally a dozen modifications of the Client-Side and Server-Side (based on lots of different methods found online), and it never hits a breakpoint in the server-side method. Most of those methods look like FM to me because I don't have a good handle on the mapping between the "web" reference to the GridController and Check4Suspensions() method as viewed from the client side - so I am mostly just trying to match up from examples.

I inherited the web app, and it is a combination of Microsoft C# Windows web application now using .NET 4.6.2, Entity Framework 6.x, JQuery 3, Kendo UI for JQuery MVC 2024.1.319, running (in Prod) under WIndows Server 2016 Standard and IIS, so there seems to be plenty of potential for difficult interactions!  Problem occurs using both Chrome and Edge (no surprise really there, same engine in both).

Thanks!

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 21 May 2024, 02:58 PM

Hello Walter,

 

Thank you for writing to us.

Your approach seems correct. The only issue I noticed is this line:

url: '@Url.Action("GridController", "ReviewSuspensions")',
You see, in MVC routing, the Controller word is usually omitted. Try to remove it and the Action should be reached successfully:
https://stackoverflow.com/questions/6119098/how-to-call-controller-actions-using-jquery-in-asp-net-mvc

I hope this information will prove helpful.

 

Regards,
Eyup
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

Tags
General Discussions
Asked by
Walter
Top achievements
Rank 2
Iron
Answers by
Eyup
Telerik team
Share this question
or