Example for DataTables Editor w/ASP.NET Core/Razor Pages

Example for DataTables Editor w/ASP.NET Core/Razor Pages

SiteserverIncSiteserverInc Posts: 6Questions: 1Answers: 0
edited June 2019 in DataTables 1.9

I've read every article matching +datatables +asp.net +core, 13 times over and can't get anywhere with getting DataTables Editor working on ASP.NET Core w/Razor Pages. Most of the examples are utilizing either ApiController (which no longer exists in ASP.NET Core), or DataTables (without the Editor). We're attempting to get this working on Razor Pages so we can continue migrating our WebForms pages to Asp.Net Core / Razor Pages.

Full MVC seemed a bit overkill/messy for us (it's a relatively small app) so the new RazorPages Syntax and smaller application footprint seems to suite our needs well. This is what we've got handling the response to the DataTables Editor code (which is also copied from our MVC App with an update to the URL string:


public JsonResult OnGetReturnQuoteItems(int QuoteID)
    MySqlConnection myConnection = new MySqlConnection(Configuration.GetConnectionString("blah"));
    using (var db = new Database("mysql", myConnection))
        var response = new Editor(db, "QuoteItems", "QuoteItemID")
             .Where("QuoteID", QuoteID, "=")
            .Process(Request.Form) // In WebForms this was .Process(Request) which .Net Core doesn't like.
        return new JsonResult(response); // In WebForms, this was return Json(response);

Our URL String in HTML is set to:

/QuoteEdit?handler=ReturnQuoteItems&QuoteID=" + getUrlVars()["QuoteID"]

If there's a better way to do this, I'd love some direction as to what we're doing wrong. Ideally we'd like to use the EF DbContext vs calling a separate DBConnection but couldn't find any good examples with that and DataTables Editor either.


This discussion has been closed.