gewusst wie: Filtern von webgrid in mvc4-basierte textbox auf Eingabe-und dropdownList-Eingang

Ich bin noch in der Lernkurve von mvc4 . Ich weiß, wie zu binden eine webgrid in mvc4 . Aber meine Frage ist kann jemand mir die Idee, wie zu binden, webgrid auf der Grundlage von filter-Bedingungen von textbox-Eingabe-und dropdownList-Eingang. Für zB : Wenn textbox ein Datum "11/15/2013" und die dropdownList hat der Arzt dem Namen "Charles" dann muss ich zeigen, in gridview-die Liste der Patienten, die hat Termin mit Arzt "charles" auf "11/15/2013" .

code

 <div id="gridContent">
 @grid.GetHtml(
 fillEmptyRows: true,
 tableStyle: "webGrid",
 alternatingRowStyle: "alternate-row",
 headerStyle: "grid-header",
    footerStyle: "grid-footer",
    mode: WebGridPagerModes.All,
     firstText: "<< First",
    previousText: "< Prev",
     nextText: "Next >",
    lastText: "Last >>",
    columns: new[] {        
    grid.Column("PatientID"),
    grid.Column("PatientName"),
    grid.Column("Age"),
    grid.Column("DOB"),
    grid.Column("Sex"),
    grid.Column("Phone"),
    grid.Column("Mobile"),
    grid.Column("City"),
    grid.Column("PinCode"),

   //grid.Column("Dr_Remarks",header:"Remarks",style:"left"),


    //grid.Column("Dr_Add1", 
    //           header: "Bed Count",style:"right"
    //),

    grid.Column("", 
                header: "Actions",
                format: @<text> 
    @Html.ActionLink("Edit", "EditPatient", new { id = item.PatientID }, htmlAttributes: new { @class = "link" })
    |
    @Html.ActionLink("Delete", "PatientList", new { id = item.PatientID },
             htmlAttributes: new { @class = "link", onclick = "return confirm('Are you sure you wish to delete this record?');" })
     </text>
    )
  })
  </div>


    **controller**

        public ActionResult PatientList(int page = 1, string sort = "Dr_Id", string sortDir = "ASC", int id = 0)
    {
        if (id != 0)
        {
            bool isDelete = false;
            isDelete = rdm_Patient.DeletePatient(id);


            return View(GetPatient(page, sort, sortDir));
        }
        else
        {
            return View(GetPatient(page, sort, sortDir));
        }
    } 

     private PatientPageViewModel GetPatient(int page = 1, string sort = "Dr_Id", string sortDir = "ASC")
    {
        const int patientPerPage = 5;
        var numPatient = rdm_Patient.CountPatient();
        sortDir = sortDir.Equals("desc", StringComparison.CurrentCultureIgnoreCase) ? sortDir : "asc";
        var validColumns = new[] { "PatientID", "PatientName" };
        if (!validColumns.Any(c => c.Equals(sort, StringComparison.CurrentCultureIgnoreCase)))
            sort = "PatientID";
        var doctors = rdm_Patient.getpatientpage(page, patientPerPage, "it." + sort + " " + sortDir);
        var data = new PatientPageViewModel()
        {

            numberOfPatient = numPatient,
            patientPerPage = patientPerPage,
            Patient = doctors,
        };
        return data;
    }

InformationsquelleAutor Murugappan | 2013-11-15

Schreibe einen Kommentar