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

In publish code, grid's read method not called

3 Answers 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samir
Top achievements
Rank 1
Iron
Samir asked on 18 Jul 2018, 03:30 PM
Created an application with Telerik Kendo UI or Asp.Net Core 2.0 controls. We used some controls which work perfectly in development. Locally we are able to run the same code without error in Visual Studio 2017, but after publishing in local IIS it gives below error( see attached image).

Error : - "http://localhost:91/Master/StateMaster/GetStateList 404 (Not Found)". 

While checking the error found that there only Read method (may be due to '[DataSourceRequest]DataSourceRequest' parameter) of a grid cannot call (  action method is perfectly called like in below code 'GetRecordStatusList()')


Our controller 
    [Area("Master")]
public class StateMasterController : Controller
    {
private IAllRepository<StateMaster> iAllStateRepository;

public IActionResult StateMaster()
{
List<SelectListItem> statusList = new List<SelectListItem>() {
new SelectListItem{Text = "Active", Value = "1" },
new SelectListItem{Text = "Inactive", Value = "2" }
};
ViewData["Status"] = statusList;

HttpContext.Session.SetInt32("UserId", 1);
HttpContext.Session.SetString("UserName", "Admin");
ViewBag.UserName = HttpContext.Session.GetString("UserName");

return View();
}

//This action method is not called in published-code
public ActionResult GetStateList([DataSourceRequest]DataSourceRequest request)
{
this.iAllStateRepository = new StateMasterRepository();
var result = iAllStateRepository.GetModelList();
var dsResult = result.ToDataSourceResult(request);
return Json(dsResult);
}

public JsonResult GetRecordStatusList()
{
List<SelectListItem> statusList = new List<SelectListItem>() {
new SelectListItem{Text = "Active", Value = "1" },
new SelectListItem{Text = "Inactive", Value = "2" }
};
return Json(statusList);
}
}


3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 23 Jul 2018, 11:03 AM
Hello Samir,

I assume that the issue is caused since the default route is matched.

e.g.

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Editions", action = "Index", id = UrlParameter.Optional }
);

Therefore the http://localhost:91/Master/StateMaster/GetStateList url the app is looking for a controller called 'Master' with an action called 'StateMaster' with a string parameter 'id' which will be set to a value of "GetStateList ".

A possible workaround is to use the Attribute Routing and configure the grid to request the specified in the Rout attribute url.

e.g.
[Route("StateMaster/GetStateList")]
public ActionResult GetStateList([DataSourceRequest]DataSourceRequest request)
{
    this.iAllStateRepository = new StateMasterRepository();
    var result = iAllStateRepository.GetModelList();
    var dsResult = result.ToDataSourceResult(request);
    return Json(dsResult);
}


Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.

0
Samir
Top achievements
Rank 1
Iron
answered on 01 Aug 2018, 09:21 AM

Hi Georgi, 

Thanks for your answer, I tried your solution, but did not help. The above code is implemented with 'Area'. 

I again ask this question with Stackoverflow with normal flow (without Area concept). We are stuck on the same with new code also. Can you help us?

https://stackoverflow.com/questions/51428535/asp-net-core-2-0-with-telerik-kendo-grid-read-method-datasourcerequest-is-no

0
Georgi
Telerik team
answered on 06 Aug 2018, 06:07 AM
Hi Samir,

I noticed that the topic in this thread is the same as in ticket with ID 1179691.

Since I have already answered in the ticket I am pasting the answer here in case someone else gets the same issue.

==========================

A common cause for the described behavior is when an exception occurs in the controller, the framework by default responds with an error page. However, in case you haven't created a error page a 404 error will occur.

Could you please wrap the logic of the read action in a try catch statement and in case an error occurs respond with some message by which you can determine whether an exception occurred?

e.g.

public ActionResult GetStateList([DataSourceRequest]DataSourceRequest request)
{
     try
    {
        this.iAllStateRepository = new StateMasterRepository();
        var result = iAllStateRepository.GetModelList();
        var dsResult = result.ToDataSourceResult(request);
        return Json(dsResult);
    }
    catch (Exception e)
    {
  
        return Json(new { error=e.Message})
    }
}

Then you can examine the request in the DevTools of your browser.


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Samir
Top achievements
Rank 1
Iron
Answers by
Georgi
Telerik team
Samir
Top achievements
Rank 1
Iron
Share this question
or