如何在不刷新页面的情况下在mvc5中应用搜索过滤器 [英] How to apply search filter in mvc5 without refreshing the page

查看:90
本文介绍了如何在不刷新页面的情况下在mvc5中应用搜索过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次点击都会刷新我的页面。我想要没有精神焕发。



我的观点是

my page is being refreshed on every click. I want without refreshed.

My View is

@using Inspinia_MVC5.Models
@model IEnumerable<Inspinia_MVC5.Models.Dashboard>

@{
    ViewBag.Title = "Dashboard_Default1";
}

@{
    IEnumerable<Dashboard> Dash = ViewData["Dashboards"] as IEnumerable<Dashboard>;
    IEnumerable<Report> Rep = ViewData["Reports"] as IEnumerable<Report>;
        
}
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Dashboard_Default</title>
    <link href="~/Content/background.css" rel="stylesheet" />
    <script src="~/Content/Script/jquery-1.4.4.min.js"></script>
    <script src="~/Scripts/jquery-2.1.1.min.js"></script>
    <script type="text/javascript">



        function changeImage(element) {
            element.src = element.bln ? "/Content/images/FavGrey.png" : "/Content/images/FavOrange.png";
            element.bln = !element.bln;
        }


        $(document).ready(function () {
            $("#txtFilter").keyup(
                function filter() {
                    debugger;
                    $.ajax({
                        type: "POST"
                    , url: "Dashboards/Filter"
                    , data: JSON.stringify({ filterText: $("#txtFilter").val() })
                    , contentType: 'application/json;'
                    , success: function (result) {
                        $("#tbldash").html(result);
                    }
                    });
                });
            });
       

    </script>
</head>
<body>

    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-6">

                        <div id="tbldash">
                               @Html.Partial("_Dashboard_Default",Model)
                           </div>                 

                    </div>
                </div>
            </div>

            
            
    

</body>
</html>





我的部分查看是(_Dashboard_Default)







My partial View is (_Dashboard_Default)


@model IEnumerable<Inspinia_MVC5.Models.Dashboard>
@{
    Layout = null;
}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5 id="header">My Dashboard </h5>
                        <div class="ibox-tools">
                            <a href="~/Dashboards/Create_Dashboard_Default">
                                <img src="~/Content/images/AddRpt.png" /></a>
                        </div>
                    </div>
                    <div class="ibox-content">
                     
                        <table class="table table-striped">

                            <thead>
                                <tr>
                                    <th>Icon
                                    </th>
                                    <th>
                                        @Html.ActionLink("DashboardID", "Dashboard_Default", new { order = ViewBag.sort_DashID })

                                    </th>
                                    <th>
                                        @Html.ActionLink("Dashboard Name", "Dashboard_Default", new { order = ViewBag.sort_DashName })
                                    </th>



                                    <th>Action</th>
                                </tr>
                            </thead>

                            <tbody>
                                @using (Html.BeginForm())
                                {
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td>
                                           <input type="text" id="txtFilter" name="search" placeholder="  Search" /><input type="submit" value="search" onclick="filter()" />
                           
                                        </td>
                                        <td></td>
                                    </tr>  
                                }
                                
                               
                                
                                @foreach (var item in Model)
                                {
                                    using (@Html.BeginForm("Delete", "Dashboards", new { id = item.DashboardID }))
                                    {
                                    <tr>
                                        <td>
                                            <img src="~/Content/images/best_fit.png" />
                                        </td>
                                        <td>
                                            @item.DashboardID
                                        </td>

                                        <td id="dashname">
                                            @item.DashboardName
                                        </td>
                                        <td>

                                            @if (@item.IsPublic == true)
                                            {
                                                <img id="fav" src="~/Content/images/FavGrey.png" /> 
                                                <a href="@Url.Action("Edit", "Dashboards", new { id = @item.DashboardID })">
                                                    <img src="~/Content/images/edit.png" /></a>
                                                <button type="submit" value="Delete" onclick="return confirm('Are you sure want to delete?')" style="border: none 0px; background-origin: padding-box; padding: 0px;">
                                                    <img src="~/Content/images/delete.png" /></button>
                                                
                                            }

                                        </td>
                                    </tr>
                                   
                                    }
                                }
                             </tbody>
                        </table>


                    </div>
                </div>
        </div>
    </div>
 </div>







我的控制器是




My controller is

[ActionName("Dashboard_Default")]
       public ActionResult Dashboard_Default_Get(string order)
       {
           RegisterLogic logic = new RegisterLogic();
           string name = Session["LoginName"].ToString();
           ViewData["UserName"] = name;  //Login Name

           logic.Name = name;  //Assigning to static variable in bussiness

           ViewData["Dashboards"] = logic.dashboardsss();
           ViewData["Reports"] = logic.reportsss();
           List<Dashboard> dash = new List<Dashboard>();
           dash = logic.dashboardsss();

           ViewBag.sort_DashID = string.IsNullOrEmpty(order) ? "OrderByID" : "";    //sorting
           ViewBag.sort_DashName = string.IsNullOrEmpty(order) ? "OrderByName" : "";
           ViewBag.sort_ByDate = order == "createdDate" ? "LasModifiedDate" : "Date";

           //if (!String.IsNullOrEmpty(search))
           //{
           //    dash = dash.Where(st => st.DashboardName.ToUpper().Contains(search.ToUpper()) || st.CreatedDate.ToString().ToUpper().Contains(search.ToUpper())).ToList();

           //}


           switch (order)
           {
               case "OrderByID":
                   dash = dash.OrderByDescending(dash1 => dash1.DashboardID).ToList();
                   break;
               case "OrederByName":
                   dash = dash.OrderByDescending(dash1 => dash1.DashboardName).ToList();
                   break;
               case "createdDate":
                   dash = dash.OrderByDescending(dash1 => dash1.CreatedDate).ToList();
                   break;
               default:
                   dash = dash.OrderBy(dash1 => dash1.DashboardID).ToList();
                   break;
           }

           return View(dash.ToList());
       }

       [HttpPost]
       [ActionName("Dashboard_Default")]
       public ActionResult Filter(string search)
       {
           RegisterLogic logic = new RegisterLogic();
           List<Dashboard> dash = new List<Dashboard>();
           dash = logic.dashboard.ToList();
           if (!String.IsNullOrEmpty(search))
           {
               dash = dash.Where(st => st.DashboardName.ToUpper().Contains(search.ToUpper()) || st.CreatedDate.ToString().ToUpper().Contains(search.ToUpper())).ToList();

           }
           return View(dash);
       }

推荐答案

document ) .ready(function () {
(document).ready(function () {


(\"#txtFilter\").keyup(
function filter() {
debugger;
("#txtFilter").keyup( function filter() { debugger;


.ajax({
type: \"POST\"
, url: \"Dashboards/Filter\"
, data: JSON.stringify({ filterText:
.ajax({ type: "POST" , url: "Dashboards/Filter" , data: JSON.stringify({ filterText:


这篇关于如何在不刷新页面的情况下在mvc5中应用搜索过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆