Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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;
- }
- Index.cshtml:
- @model MvcApplication1.Models.Employee
- @{
- ViewBag.Title = "Index";
- }
- <h2>Index</h2>
- <table>
- <tr>
- <td>
- @Html.DropDownList("lstdepartment", Model.Department_List)
- </td>
- </tr>
- <tr>
- <td>
- <div id="EmployeeViewGrid">
- @Html.Partial("EmployeeView",Model.Employee_Grid)
- </div>
- </td>
- </tr>
- </table>
- <script type="text/javascript">
- $('#lstdepartment').change(function (e) {
- e.preventDefault();
- var url = '@Url.Action("Filter")';
- $.get(url, { department: $(this).val() }, function (result) {
- debugger;
- $('#EmployeeViewGrid').html(result);
- });
- });
- </script>
- Partial view:
- @model List< MvcApplication1.Models.Employee>
- @{
- ViewBag.Title = "EmployeeView";
- }
- <h2>EmployeeView</h2>
- <div id="gridposition" style="overflow: scroll; height: 300px; overflow-x: hidden;">
- @{
- var grid1 = new WebGrid(source: Model, canPage: true, rowsPerPage: 5, ajaxUpdateContainerId: "gridContent");
- @grid1.GetHtml(mode: WebGridPagerModes.All, tableStyle: "webGrid",
- headerStyle: "header",
- alternatingRowStyle: "alt",
- selectedRowStyle: "select",
- rowStyle: "description",
- htmlAttributes: new { id = "positionGrid" },
- fillEmptyRows: false,
- columns: grid1.Columns(
- grid1.Column("EmployeeId", header: "EmployeeId"),
- grid1.Column("EmpName", header: "EmpName"),
- grid1.Column("Age", header: "Age"),
- grid1.Column("Department", header: "Department"),
- grid1.Column("Salary", header: "Salary")))
- }
- </div>
- Controller:
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.Entity;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using MvcApplication1.Models;
- namespace MvcApplication1.Controllers
- {
- public class EmployeeController : Controller
- {
- private EmployeeDatabaseEntities1 db = new EmployeeDatabaseEntities1();
- //
- // GET: /Employee/
- public ActionResult Index()
- {
- Employee _model = new Employee();
- //_model.Employee_Grid = db.tbl_Employee.ToList();
- var departmentlist = db.tbl_department.ToList();
- _model.Department_List = (from d in departmentlist
- select new SelectListItem
- {
- Value = d.department_id.ToString(),
- Text = d.department_name
- }).ToList();
- var qq = (from e in db.tbl_Employee
- join d in db.tbl_department on e.Department_id equals d.department_id
- select new Employee
- {
- Department_id=e.Department_id,
- EmployeeId=e.EmployeeId,
- EmpName=e.EmpName,
- Age=e.Age,
- Department=d.department_name
- }).ToList();
- _model.Employee_Grid = qq;
- return View("Index", _model);
- }
- public ActionResult Filter(string department)
- {
- int? department_id = Convert.ToInt32(department);
- var qq = (from e in db.tbl_Employee
- join d in db.tbl_department on e.Department_id equals d.department_id
- where e.Department_id == department_id
- select new Employee
- {
- Department_id = e.Department_id,
- EmployeeId = e.EmployeeId,enter code here
- EmpName = e.EmpName,
- Age = e.Age,
- Department = d.department_name
- }).ToList();
- return PartialView("EmployeeView",qq);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement