我对Webgrid进行了部分删除操作,但是删除后,我的Webgrid却没有刷新
我需要访问数据库并刷新网格,而不仅仅是隐藏tr
我尝试使用JavaScript运行控制器的索引,但是我的网络网格仍然没有刷新
webGrid代码
@webGrid.GetHtml(
htmlAttributes: new { @id = "WebGrid", @class = "data-grid" },
columns: webGrid.Columns(
webGrid.Column(format: @<span class="hideID">@item.ID</span>, style: "ID"),
webGrid.Column(format: @<span class="hidePath">@item.DocumentPath</span>, style: "ID"),
webGrid.Column(header: "Document", format: @<span><span class="label">@item.Documentname</span>
<input class="text" type="text" value="@item.Documentname" style="display:none"/></span>, style: "Document"),
webGrid.Column(header: "Date", format: @<span><span class="label">@item.AttachedTime</span>
<input class="text" type="text" value="@item.AttachedTime" style="display:none"/></span>, style: "Date"),
webGrid.Column(header: "Added by", format: @<span><span class="label">@item.AddedBy</span>
<input class="text" type="text" value="@item.AddedBy" style="display:none"/></span>, style: "Added by"),
webGrid.Column(header: "Related To", format: @<span><span class="label">@item.Reletedto</span>
<input class="text" type="text" value="@item.Reletedto" style="display:none"/></span>, style: "Related To"),
webGrid.Column(format: @<span class="link">
<a class="Download" href="javascript:;">Download</a>
</span>),
webGrid.Column(format: @<span class="link">
<a class="Delete" href="javascript:;">Delete</a>
</span>)))
JavaScript代码
$("body").on("click", "#WebGrid TBODY .Delete", function () {
debugger;
if (confirm("Do you want to delete this row?")) {
var row = $(this).closest("tr");
var ID = row.find(".hideID").html();
$.ajax({
type: "POST",
url: "/Home/Delete",
data: '{ID: ' + ID + '}',
contentType: "application/json; charset=utf-8",
cache: false,
dataType: "json",
success: function (response) {
Refresh()
}
});
}
});
function Refresh() {
$("#WebGrid").load("Home\Index");
}
控制器代码
[OutputCache(Duration = 0, VaryByParam = "*")]
public ActionResult Index()
{
List<AttachedDocumnet> Document = load();
return View(Document);
}
private static List<AttachedDocumnet> load()
{
NHSEntities entities = new NHSEntities();
List<AttachedDocumnet> Document = entities.AttachedDocumnets.ToList();
return Document;
}