我试图使用javascript调用ViewComponent来促进页面加载,现在我使用razor调用了viewcomponent但是页面加载需要很长时间,怎么做?
这是控制器中的方法:
public async Task<IViewComponentResult> InvokeAsync(string id)
{
//var notifications = _context.Notifications.Include(m => m.ApplicationUser).Include(m => m.Sender).OrderByDescending(m => m.Id);
return View(await _context.Follows.Include(f=>f.User.University).Include(f=>f.User.Faculty).Where(n=>n.FollowedUserId==id).ToListAsync());
}
Run Code Online (Sandbox Code Playgroud)
和方法调用(jQuery):
<script>
$(document).ready(function () {
$('#viewallfollowers').click(
function () {
$("#followersrefresh").load("@await Component.InvokeAsync("Follower", new { id=Model.ApplicationUser.Id })");
});
});
</script>
Run Code Online (Sandbox Code Playgroud)