where condition not a field .net

where condition not a field .net

montoyammontoyam Posts: 115Questions: 32Answers: 3
edited February 13 in Free community support

I am filtering a second datatable based off a selected row of the first database. However, if there is nothing selected on the first datatable, I would like the second datatable to show all records. Is this possible? Currently, if unselected I am settting it to -1.

            ajax: {
                url: '/api/Contacts',
                type: 'post',
                data: function (d) {
                    var selected = applicationtable.row({ selected: true });
                    if (selected.any()) {
                        d['Contacts.ApplicationID'] = selected.data().ApplicationID;
                    } else {
                        d['Contacts.ApplicationID'] = -1;
                    }
                }
            },

it doesn't like the orWhere because it is expecting a fieldname

                                .Where(q =>
                                {
                                    q.Where(r =>
                                    {
                                        r.Where("Contacts.ApplicationID", request.Form["Contacts.ApplicationID"]);
                                        r.OrWhere(request.Form["Contacts.ApplicationID"],"-1");
                                    });
                                })

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 51,411Questions: 1Answers: 7,752 Site admin
    edited February 13 Answer ✓

    I'd say only add the Where condition if the value of the application id is not -1, unless I've misunderstood?

    if(request.Form["Contacts.ApplicationID"] != "-1") {
      q.Where(...);
    }
    

    Allan

  • montoyammontoyam Posts: 115Questions: 32Answers: 3

    thank you so much. I should have thought of that!!

                                    .Where(q =>
                                    {
                                        if (request.Form["Contacts.ApplicationID"] != "-1")
                                        {
                                            q.Where("Contacts.ApplicationID", request.Form["Contacts.ApplicationID"]);
                                        }
                                    })
    
Sign In or Register to comment.