I am viewing my records on the index with a PagedList
// GET: Product
public ActionResult Index(int page = 1)
{
int recordsPerPage = 1; //Page size = 1 record
var productList = db.q_product.ToList().ToPagedList(page, recordsPerPage);
return View(productList);
}
when viewing the records on the page the fields are editable as seen in the image below
The functionality I am trying to create is to be able to edit any field and click save which will in turn update that record in the database and return me back to that same record after post/click save event.
<div class="form-group" style="float: left;">
<input type="submit" value="Save" class="btn btn-default" />
</div>
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Save(q_product q_product, int page = 1)
{
if (!ModelState.IsValid)
{
int recordsPerPage = 1;
var productList = db.q_product.ToList().ToPagedList(page, recordsPerPage);
return View(productList);
}
else
{
db.Entry(q_product).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
}
How do I got about achieving this functionality?
EDIT:
The records are in a form as seen with the following code
<h4>PRODUCT VIEW</h4>
@foreach (var item in Model)
{
using (Html.BeginForm("Save", "Product"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.FirstOrDefault().q_guid)
<div class="panel panel-default">
<div class="panel-heading">PRODUCT INFORMATION</div>
<div class="row">
<div class="col-lg-4">
<div class="panel-body">
<div class="form-group">
<dt>
@Html.DisplayNameFor(model => model.FirstOrDefault().q_barcode)
</dt>
<dd>
@Html.EditorFor(modelItem => item.q_barcode)
</dd>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="panel-body">
<div class="form-group">
<dt>
@Html.DisplayNameFor(model => model.FirstOrDefault().q_description)
</dt>
<dd>
@Html.EditorFor(modelItem => item.q_description)
</dd>
</div>
</div>
</div>