I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
In this article i will show you, how to remove duplicates in DropdownList when it appear on browser window. If you have multiple item in the table and you want to show only distinct items of the table then you can use siblings function of the JQuery. Lets check the simple example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.10.2.js"></script>
<script>
$(function () {
$("select option").each(function () {
$(this).siblings("[value=" + this.value + "]").remove();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<h2>How to Remove duplicate dropdown option elements with same value</h2>
<div><select name="selectlist">
<option value="">Fruit List</option>
<option value="1">Apple</option>
<option value="2">Mango</option>
<option value="1">Grapes</option>
<option value="2">Orange</option></select>
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.10.2.js"></script>
<script>
$(function () {
$("select option").each(function () {
$(this).siblings("[value=" + this.value + "]").remove();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<h2>How to Remove duplicate dropdown option elements with same value</h2>
<div><select name="selectlist">
<option value="">Fruit List</option>
<option value="1">Apple</option>
<option value="2">Mango</option>
<option value="1">Grapes</option>
<option value="2">Orange</option></select>
</div>
</form>
</body>
</html>
Code Generate the following output:
Comments
Post a Comment