Datatables with Razor Pages

Datatables with Razor Pages

StormchaserStormchaser Posts: 2Questions: 1Answers: 1

Howdy folks!

My company is considering to move over from MVC to Core 2.1 Razor Pages, I have been tasked to see if there will be any hick ups during this transition. We've made use of Datatables in previous applications however I cannot find anything with regards to how to get it to work with Razor pages? Can someone please point me in the right direction?

Many Thanks.

This question has an accepted answers - jump to answer

Answers

  • StormchaserStormchaser Posts: 2Questions: 1Answers: 1
    Answer ✓

    Ah nevermind, I got it to work.

  • SiteserverIncSiteserverInc Posts: 6Questions: 1Answers: 0

    Eh, how? ;)

  • SiteserverIncSiteserverInc Posts: 6Questions: 1Answers: 0

    Particularly, I'm trying to find some examples of DataTables editor used with ASP.Net Core Razor Pages...

  • colincolin Posts: 15,154Questions: 1Answers: 2,587

    There's a quite a few pages discussing this if you do a web search, such as this and this. Hopefully they'll help,

    Cheers,

    Colin

  • SiteserverIncSiteserverInc Posts: 6Questions: 1Answers: 0
    edited June 2019

    Thank you Colin, I've read every article matching +datatables +asp.net +core, 13 times over and can't get anywhere. 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:

    [HttpGet]

        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")
                     .Model<Models.blah.QuoteItems>()
                     .Where("QuoteID", QuoteID, "=")
    
                    .Process(Request.Form) // In WebForms this was .Process(Request) which .Net Core doesn't like.
                    .Data();
                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.

  • SiteserverIncSiteserverInc Posts: 6Questions: 1Answers: 0

    I asked this question in a new post so it can hopefully help others as ours is specific to DataTables Editor w/ASP.NET Core / Razor Pages. For whatever reason, it doesn't give us the option to post in the Editor forum.

  • allanallan Posts: 61,771Questions: 1Answers: 10,112 Site admin

    Most of the examples are utilizing either ApiController (which no longer exists in ASP.NET Core)

    In the "Controllers" section at the bottom of this page it shows how to use .NET Core controllers. The .NET Core download package for Editor also includes a full set of examples for .NET Core, including their controllers.

    EF DbContext vs calling a separate DBConnection but couldn't find any good examples with that and DataTables Editor either

    Editor uses a direct ADO.NET connection rather than EF I'm afraid.

    Allan

  • kamal94kamal94 Posts: 1Questions: 0Answers: 0
    edited August 2020

    hi team and @Stormchaser,

    I was using this datatables from 2018. now I have to work on asp.net razor pages.
    and the response data is too large, so I decided to use serverside rendering.

    the issue is that I'm not able to make it work. I get no help from google or any other articles.

    I need some help from you guys to implement datatable server-side rendering using asp.net core razor pages.

    kindly help ..

    thanks in advance,
    kamal.

This discussion has been closed.