我有这张桌子:
这基本上是foreach
在.cshtml
带有<tr><td>
append的情况下加载的。当我单击一个文件夹时,它应该为我获取内容并用新的内容重新加载表。我.ajax
用来获取内容,并window.location.href
用来重新加载页面。但是,使用确实需要很多时间来重新加载页面location.href
。页面的性能也很差,因为它再次调用上的服务器端代码location.href
。您对这种情况有何建议?
您说了有关.cshtml的内容,所以我将尝试向您解释我如何在asp.net mvc中执行此操作。
您说您正在使用ajax调用。没关系。
请创建局部视图(http://www.codeproject.com/Tips/617361/Partial-View-in-ASP-NET-MVC),该视图将用于为您提供文件视图的html。在您的动作中(您从ajax调用)
public JsonResult RenderFilesView(int renderMyFolderId){
var folderModelWithFiles = this._repository.GetFolderAndFilesModel(renderMyFolderId);
var filesViewHtml = this.RenderRazorViewToString("_FilesView", folderModelWithFiles);
return Json(new { FilesViewHtml = filesViewHtml });
}
RenderPartialViewToString此处:将部分视图渲染为字符串MVC4
并且您将在ajax的成功功能中收到称为FilesViewHtml的信息。
$.ajax( url: 'godKnows/RenderFilesView',
success: function(response){
// access response.FilesViewHtml
// And you can do something like:
$('#container').html(response.FilesViewHtml);
});
无需重新加载页面,否则上帝知道什么。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句