Hello everyone,
I am working on mvc 5 project i want to be able to display webgrid on button click event, that is, i have a search button on the view, i want to display search results on the webgrid if the record(s) is/are found.
below is my code:
public ActionResult ValidateReceipt()
{
return View();
}
[HttpPost]
public ActionResult ValidateReceipt(Payment_History payment)
{
var receiptSerialNo =
(from r in db.Payment_History where (r.pin_serial_no == payment.pin_serial_no) select r).FirstOrDefault();
var studentsReciept = new List<Payment_History>();
if (receiptSerialNo != null)
{
studentsReciept.Add(new Payment_History { surname = receiptSerialNo.surname, amount_paid = receiptSerialNo.amount_paid, school_fees_pin = receiptSerialNo.school_fees_pin, term = receiptSerialNo.term});
ViewBag.ValReceipt = studentsReciept;
}
return View(studentsReciept);
}
View Code:
@{
var obj = new WebGrid(ViewBag.ValReceipt, canPage : true, canSort : false, rowsPerPage : 1);
obj.Pager(WebGridPagerModes.All);
}
@obj.GetHtml(tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
rowStyle: "webgrid-row-style",
columns: obj.Columns(
obj.Column("pin_serial_no", "Fee SerialNo"),
obj.Column("School_fees_pin", "PIN"),
obj.Column("surname", "Surname"),
obj.Column("first_name", "Firstname"),
obj.Column("amount_paid", "Fee"),
obj.Column("session_year", "Session"),
obj.Column("term", "Term"),
obj.Column("class", "Class")
))
Thanks for your help.