Làm bài test nhanh kiểm tra lại kiến thức java cơ bản với 59 câu hỏi tại w3schools.com
Mời bạn vào link sau:
Làm bài test nhanh kiểm tra lại kiến thức java cơ bản với 59 câu hỏi tại w3schools.com
Mời bạn vào link sau:
Đố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);
}
Trong MVC, ngoài những ValidationAttribute có sẵn như Required, Display ..
Đôi khi bạn cần gọi hàm check riêng của bạn cho 1 field name nào đó
ví dụ class:
public class AccountDTO
{
/// <summary>
/// Tên đăng nhập
/// </summary>
[Required(ErrorMessage = "Nhập tên đăng nhập")]
[Display(Name = "Tên đăng nhập")]
[CheckUsernameAvailable]
public string Username { get; set; }
//những field khác ....
}
Hãy lưu ý: CheckUsernameAvailable
cần kiểm tra username có ai sử dụng hay chưa
Ta có class tương ứng
Anh em làm dev với cơ sở dữ liệu sql server chắc không ai không cần dùng SSMS đâu nhỉ
Tất nhiên miễn phí và chất lượng, hàng của MS mà ;)
link thông tin SSMS: https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms
link download bản mới nhất: https://aka.ms/ssmsfullsetup
Mai đi làm ngày đầu tiên ở cty mới sau 3 năm cày cuốc freelance và mở cty chưa đủ tài ...
Lại làm thuê kiếm bia uống...
//định nghĩa class chia trang thường dùng
public class Pager
{
public Pager(
int totalItems,
int currentPage = 1,
int pageSize = 10,
int maxPages = 10)
{
// calculate total pages
var totalPages = (int)Math.Ceiling((decimal)totalItems / (decimal)pageSize);
// ensure current page isn't out of range
if (currentPage < 1)
{
currentPage = 1;
}
else if (currentPage > totalPages)
{
currentPage = totalPages;
}
int startPage, endPage;
if (totalPages <= maxPages)
{
// total pages less than max so show all pages
startPage = 1;
endPage = totalPages;
}
else
{
// total pages more than max so calculate start and end pages
var maxPagesBeforeCurrentPage = (int)Math.Floor((decimal)maxPages / (decimal)2);
var maxPagesAfterCurrentPage = (int)Math.Ceiling((decimal)maxPages / (decimal)2) - 1;
if (currentPage <= maxPagesBeforeCurrentPage)
{
// current page near the start
startPage = 1;
endPage = maxPages;
}
else if (currentPage + maxPagesAfterCurrentPage >= totalPages)
{
// current page near the end
startPage = totalPages - maxPages + 1;
endPage = totalPages;
}
else
{
// current page somewhere in the middle
startPage = currentPage - maxPagesBeforeCurrentPage;
endPage = currentPage + maxPagesAfterCurrentPage;
}
}
// calculate start and end item indexes
var startIndex = (currentPage - 1) * pageSize;
var endIndex = Math.Min(startIndex + pageSize - 1, totalItems - 1);
// create an array of pages that can be looped over
var pages = Enumerable.Range(startPage, (endPage + 1) - startPage);
// update object instance with all pager properties required by the view
TotalItems = totalItems;
CurrentPage = currentPage;
PageSize = pageSize;
TotalPages = totalPages;
StartPage = startPage;
EndPage = endPage;
StartIndex = startIndex;
EndIndex = endIndex;
Pages = pages;
}
public int TotalItems { get; private set; }
public int CurrentPage { get; private set; }
public int PageSize { get; private set; }
public int TotalPages { get; private set; }
public int StartPage { get; private set; }
public int EndPage { get; private set; }
public int StartIndex { get; private set; }
public int EndIndex { get; private set; }
public IEnumerable<int> Pages { get; private set; }
}
//cách dùng trong mvc razor view
//css boostrap mặc định
if (pager != null && pager.Pages.Any())
{
<nav class="table-responsive">
<ul class="pagination justify-content-center d-flex flex-wrap">
@if (pager.CurrentPage > 1)
{
<li class="page-item">
<a class="page-link" href="@Url.Action("Index", "Home")">Trang đầu</a>
</li>
<li class="page-item">
<a class="page-link" href="@Url.Action("Index", "Home")?p=@(pager.CurrentPage - 1)">Trước</a>
</li>
}
@foreach (var p in pager.Pages)
{
<li class="page-item @(p == pager.CurrentPage ? "active" : "")">
<a class="page-link" href="@Url.Action("Index", "Home")?p=@p">@p</a>
</li>
}
@if (pager.CurrentPage < pager.TotalPages)
{
<li class="page-item">
<a class="page-link" href="@Url.Action("Index", "Home")?p=@(pager.CurrentPage + 1)">Tiếp</a>
</li>
<li class="page-item">
<a class="page-link" href="@Url.Action("Index", "Home")?p=@(pager.TotalPages)">Trang cuối</a>
</li>
}
</ul>
</nav>
}
Chính thức trở thành đơn vị cung cấp dịch vụ đăng ký tên miền quốc tế, tên miền Việt Nam hosting, máy chủ, cloud hosting, cloud server, ema...