I created a functionality to delete a specific row in my webgrid table. This works fine but when the row is deleted I want my view to get refreshed and shows the actual data(after deleting a row).
This is what I got so far:
Webgrid view including link-tag that calls my controller and sends parameter ID with it.
<div class="col-lg-12 d-flex align-items-stretch">
@grid.Table(tableStyle: "table table-responsive table-striped table-bordered",
columns: grid.Columns(
grid.Column(columnName: "ApiRedirectID", header: "ID", format:@<text><div class="" data-id="@item.ApiRedirectID" data-propertyname="ApiRedirectID">@item.ApiRedirectID</div></text>),
grid.Column(columnName: "ApiName", header: "Name", format:@<text><div class="edit" data-id="@item.ApiRedirectID" data-propertyname="ApiName">@item.ApiName</div></text>),
grid.Column(columnName: "Company.CompanyName", header: "Company Name", format:@<text><div class="edit" data-id="@item.ApiRedirectID" data-propertyname="Company.CompanyName">@item.Company.CompanyName</div></text>),
grid.Column(columnName: "ApiURL2", header: "URL", format:@<text><div class="edit" data-id="@item.ApiRedirectID" data-propertyname="ApiURL2">@item.ApiURL2</div></text>),
grid.Column(columnName: "Delete", header: " ", format:@<a href="DeleteRow/@item.ApiRedirectID" class="display delete-btn"><span class="glyphicon glyphicon-remove" style="color:red;"></span></a>)
)
)
</div>
Controller that handles the deleting part:
public ActionResult DeleteRow(int id)
{
var status = false;
var message = "";
using (ConcurrentDBEntities db = new ConcurrentDBEntities())
{
var data = db.ApiRedirects.Find(id);
if (data != null)
{
db.ApiRedirects.Remove(data);
db.SaveChanges();
status = true;
}
else
{
message = "Error!";
}
var response = new { id = id, status = status, message = message };
JObject o = JObject.FromObject(response);
return Content(o.ToString());
}
This code works fine but when I delete a row the following is getting returned:
Instead of this I just want my view with my updated webgrid table getting returned.
Hope anyone can help!