jquery datatables (bower) asp.net mvc 6 server side processing not working

jquery datatables (bower) asp.net mvc 6 server side processing not working

ar27111994ar27111994 Posts: 5Questions: 1Answers: 0
edited April 2016 in Free community support

I've tried this famous link (although written for mvc5) but it doesn't work in mvc 6. Please can anyone provide some instructions for doing the same as done in the link but in aspnet mvc 6? I get the following error when running the code provided for mvc5 in my mvc6 project:
Error Image

and the following javascript errors.
Error Image

This question has an accepted answers - jump to answer

Answers

  • ar27111994ar27111994 Posts: 5Questions: 1Answers: 0

    So no one interested :'(

  • allanallan Posts: 63,839Questions: 1Answers: 10,518 Site admin

    Hi,

    I'm not sure if the author of the article you linked to reads this forum, so if you are having problems with the instructions in that post you might want to ask in their comments section.

    The error you are seeing is coming from the server-side (DataTables is just reporting the error):

    Object reference not set to an instance of an object

    Possibly it is as simple as a new operator missing, but I'm afraid I don't know MVC6 well. You'd need to ask in an MVC forum as it doesn't appear to be a client-side problem.

    Allan

  • ar27111994ar27111994 Posts: 5Questions: 1Answers: 0

    Thanks Allan, actually, I found this article on your website. Secondly the javascript errors that I mentioned say that the columns property of oTable is undefined:

    Cannot read property 'every' of undefined .

    which is oTable's columns property in my case.

  • allanallan Posts: 63,839Questions: 1Answers: 10,518 Site admin

    Hi,

    The article you linked to is on echosteg.com not datatables.net. I'm afraid I don't know the author of the article.

    Can you link to your page so I can debug the Javascript errors please? However, I suspect you'll need to fix the server-side issue first.

    Allan

  • ar27111994ar27111994 Posts: 5Questions: 1Answers: 0

    the link to that article*
    http://datatables.net/news/

    see "Server-side with ASP.NET MVC 5" on this page.

    Unfortunately No I can't, as I'm developing on localhost.

  • allanallan Posts: 63,839Questions: 1Answers: 10,518 Site admin
    Answer ✓

    Thanks for clarifying that its a link to am external site. I'm afraid that I can't offer stuff for information provided on an external site, even if it is linked here. That would make for an extraordinary amount of work for free software! I linked to it in good faith that it worked for the versions mentioned in the article. I sounds like it might need an update for new versions. As I say you would need to contact the author, or I'm sure if you were to debug it and update the code and post your solution others would find it useful.

    On the client side I'm afraid I can't offer any help without a test case, since I have no way of debugging the issue. I'm happy to help there, but need to be able to see the issue to be able to offer any advice!

    Allan

  • cynxcynx Posts: 2Questions: 0Answers: 0

    Hi, I am the author of the post. The example I have posted was developed and tested with MVC 5 (as I have mentioned in the article title). It may not work with MVC 6 'as-is'. You may have to make changes. Unfortunately I have not worked with MVC 6 yet. However, if you can upload and share the MVC 6 solution, I am certainly happy to help...

    Cheers.

  • allanallan Posts: 63,839Questions: 1Answers: 10,518 Site admin

    @cynx - Thanks for finding this thread and posting back - much appreciated!

    Allan

  • ar27111994ar27111994 Posts: 5Questions: 1Answers: 0
    edited April 2016

    Thank you @allan and @cynx for responding on this topic. I've not been doing doing this stuff lately. I'll try to inspect the problems in Api trough Postman and post the results. Meanwhile all I can say is that I'd to replace SortBy with OrderBy in ResultSet.cs

    public List<Product> GetResult(string search, string sortOrder, int start, int length, List<Product> dtResult, List<string> columnFilters)
            {
                string[] orderParam = sortOrder.Split(' ');
    
                if (string.IsNullOrWhiteSpace(orderParam[1]))
                    return FilterResult(search, dtResult, columnFilters).OrderBy(i => i.GetType().GetProperty(orderParam[0].Trim()).GetValue(i, null)).Skip(start).Take(length).ToList();
    
                return FilterResult(search, dtResult, columnFilters).OrderByDescending(i => i.GetType().GetProperty(orderParam[0].Trim()).GetValue(i, null)).Skip(start).Take(length).ToList();
    
            }
    

    with the corresponding changes to SortOrder Property of DTResult Class to get compiled.

    public string SortOrder
            {
                get
                {
                    return Columns != null && Order != null && Order.Length > 0
                        ? (Columns[Order[0].Column].Name + (Order[0].Dir == DTOrderDir.DESC ? " " + Order[0].Dir : string.Empty))
                        : null;
                }
            }
    
  • tdktdk Posts: 32Questions: 16Answers: 0

    @ar27111994 Did you get anywhere with the MVC 6 solution?

This discussion has been closed.