简体   繁体   中英

Help with jquery grid in asp.net mvc

I have followed Phil Haack's tutorial and everything works fine but now I want to implement search filters in my grid and I noticed that it sends a filter string attribute with my search string to my controller but its in json format... I have no idea how to get the values and use them to implement my search function..., Im using linq to sql.... please help

Right now Im just trying to implement a search by name function of Companies. I have a Company linq to sql model. I want the search to use SQL Like... so if I have a Company with the name of "Ford" and I type "For" it should find the company Ford and return it to the grid.

I don't have a lot of time to answer this sorry so here is code I implemented. Hope this helps you out. Leave a comment if it doesn't and I'll try to explain it.

In the view;

function filterBy(filter) {
    $.post("/Admin/jQueryUserFilter", { filterBy: filter }, function(newUserListHTML) {
    $("#divUsers").fadeOut(300, function() {
        document.getElementById("divUsers").innerHTML = newUserListHTML;
    });

    $("#divUsers").fadeIn(300);
});
}


<input type="submit" value="Find User" onclick="filterBy(document.getElementById('txtFor').value);return false;" />

In my controller;

public ActionResult jQueryUserFilter(string filterBy)
{
    AdminRepository<User> adminRepository = new AdminRepository<User>();
    IQueryable<User> users;

    if (filterBy == "**all**")
        users = adminRepository.All().OrderBy(x => x.userName);
    else
        users = adminRepository.All().Where(u => u.userName.StartsWith(filterBy)).OrderBy(x => x.userName);
    return PartialView("UserList", users);
}

check the link below it should come up pretty handy,

table grid mvc3 and jquery paging and filter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM