Reputation: 1
I am working an asp.net MVC web application, and inside my view, i have a webgrid as follow:-
@model T.ViewModels.GridList<T.Models.Resources>
var gridcolumns = new List<WebGridColumn>();
gridcolumns.Add(new WebGridColumn()
{
CanSort = false,
Format =
(item) =>
{
var banner = item.Value as T.Models.Resources;
return Ajax.ActionLink("Delete", "Delete", banner.Technology.TechnologyType.Name, new { id = banner.TechnologyID },
new AjaxOptions
{
Confirm = "Are You sure You want to delete (" + banner.Technology.Tag.ToString() + ")",
HttpMethod = "Post",
OnSuccess = "deletionconfirmation",
OnFailure = "deletionerror"
});
}
});
var grid = new WebGrid(
canPage: true,
rowsPerPage: Model.PageSize,
canSort: true,
ajaxUpdateContainerId: "grid");
grid.Bind(Model.Content, rowCount: Model.TotalRecords, autoSortAndPage: false);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id = "grid" }, // id for ajaxUpdateContainerId parameter
fillEmptyRows: false,
tableStyle: "table table-bordered table-hover",
mode: WebGridPagerModes.All,
columns: gridcolumns
);
now the web grid will be generating an HTML table with rows. and as shown on my above sample code, i have an Ajax.ActionLink
to delete a row, and i am passing the item ID. then inside the OnSuccess = "deletionconfirmation"
function i will be removing the related row, as follow:-
function deletionconfirmation(data)
{
if (data.IsSuccess == "reload") {
location.reload();
}
if (data.IsSuccess == "True") {
$('#' + data.id).remove();
$.fn.jAlert({
'title': 'Deletion Confirmation',
'message': data.description + ' deleted successfully',
'theme': 'success',
'clickAnywhere': false
});
}
But my problem is how i can add the items ids inside the WebGrid to be the ids of the generated rows?
Upvotes: 0
Views: 25
Reputation: 218732
The this
expression inside the deletionconfirmation
method will give you the anchor tag HTML element user clicked to start the ajax call. You can use the jQuery closest
method to get the outer TR of that.
function deletionconfirmation(data) {
var $tr = $(this).closest("tr");
//Do your if conditions to check the data property to determine what to do next.
$tr.fadeOut(400);
}
Upvotes: 1