Đối với trang web có nhiều phần nội dung khác nhau,
ví dụ:
1) header
2) body
2.1) left
2.2) center
2.3) right
3) footer
Để tăng thời gian hiển thị nội dung trang web lên giao diện cho thân thiên với người dùng thay vì load 1 lần ta có thể thực hiện load từng phần riêng lẻ với partial view
Đoạn code sau thể hiện load footer
1) Trên view layout
<script>
$(document).ready(function() {
//dùng jquery thực hiện load action FooterContents trong controller Home
//vào div có id là partialFooter
$("#partialFooter").load('@Url.Action("FooterContents", "Home")');
});
</script>
2) Trong code behind controller Home, action FooterContents
public async Task<ActionResult> FooterContents()
{
List<ObjectDTO> objDTOs = new List<ObjectDTO>();
try
{
//uow call bll to get data from database
objDTOs = await unitOfWork.Entity.GetList(20);
//do some things..
}
catch(Exception ex)
{
//handle exception
}
//display listing
return PartialView("FooterContents", objDTOs);
}