Как отфильтровать поиск в вашем View, используя обработку на стороне сервера? - PullRequest
0 голосов
/ 10 февраля 2020

введите описание изображения здесь У меня есть вид и список полей из таблицы в моей базе данных, я использую dataTable, но я хочу реализовать свой поиск, чтобы отфильтровать все доступные имена полей из таблицы , Когда они недоступны, должны иметь возможность читать из базы данных. У меня нет опыта, чтобы сделать это, могут ли товарищи показать мне примеры, чтобы сделать это, пожалуйста. Ниже моя логика c на стороне вида, есть ли способ и на классе контроллера? если так, пожалуйста, покажи мне.

    // Index.cshmtl

    @{
        ViewBag.Title = "EventManagement List";
    }
    <hr/>
    <hr/>
    <hr/>
    <h2>EventManagement List</h2>
    <table id="EventManagementTable" class="display">
        @*Semantic UI*@
        @*<table id="EventManagementTable" class="ui celled table">*@
        @*Bootstrap*@
        @*<table id="EventManagementTable" class="table table-striped table-bordered">*@

        <thead>
            <tr>
                <th>TrainingID</th>
                <th>TrainingType</th>
                <th>TrainingDescription</th>
                <th>Price</th>
                <th>Venue</th>
                <th>Facilitator</th>
                <th>WhoAttend</th>
                <th>RSVP</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>TrainingID</th>
                <th>TrainingType</th>
                <th>TrainingDescription</th>
                <th>Price</th>
                <th>Venue</th>
                <th>Facilitator</th>
                <th>WhoAttend</th>
                <th>RSVP</th>
            </tr>
        </tfoot>

    </table>


    <!--Normal DataTables-->
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.20/datatables.min.css" />

    <!---JQuery ThemeRoller-->
    <link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
    <link href="https://cdn.datatables.net/1.10.15/css/dataTables.jqueryui.min.css" rel="stylesheet" />

    <!--Semantic UI-->
    <link href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.min.css" rel="stylesheet" />
    <link href="https://cdn.datatables.net/1.10.15/css/dataTables.semanticui.min.css" rel="stylesheet" />

    <!-- Bootstrap 4 -->
    <link href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap4.min.css" rel="stylesheet" />

    @section scripts{

        <script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
        <script src="https://cdn.datatables.net/1.10.15/js/dataTables.jqueryui.min.js"></script>
        <script src="https://cdn.datatables.net/1.10.15/js/dataTables.semanticui.min.js"></script>
        <link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0.0-alpha.6/css/bootstrap.css" rel="stylesheet"/>
        <script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap4.min.js"></script>

        <script>

         $(document).ready(function () {

                $("#EventManagementTable").DataTable(
                    {
                        "ajax": {
                            "url": "/EventManagement/GetList",
                            "type": "GET",
                            "datatype": "json"
                        },
                        "columns": [
                            { "data": "TrainingID" },
                            { "data": "TrainingType" },
                            { "data": "TrainingDescription" },
                            { "data": "Price" },
                            { "data": "Facilitator" },
                            { "data": "WhoAttend" },
                            {"data":"RSVP"}
                        ],

  "serverSide": "true",
                    "order": [0, "asc"],
                    "processing": "true",
                    "language": {
                        "processing":"processing...... please wait"
                    }


                    });

            });
        </script>


        }
// Controller
 [HttpPost]
       public ActionResult GetList()
        {
            //Server side Parameter.
            int start = Convert.ToInt32(Request["start"]);
            int length = Convert.ToInt32(Request["length"]);
            string searchValue = Request["search[value]"];
            string sortColumnName = Request["columns[" + Request["order[0][column]"] + "][name]"];
            string sortDirection = Request["order[0] [dir]"];





            return View();
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...