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 }); }
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 });
}
return View(allUsers);
}
}
Second View Component
public class StudentsViewComponent : ViewComponent
{
private readonly UserManager<ApplicationUser> _userManager;
public StudentsViewComponent(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
public async Task<IViewComponentResult> InvokeAsync()
{
List<StudentViewModel> students = new List<StudentViewModel>();
var items = await _userManager.GetUsersInRoleAsync("Student");
foreach (var item in items)
{
students.Add(new StudentViewModel {EnrollmentNo=item.EnrollmentNo,FatherName=item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });
}
return View(students);
}
}
Third View Component
public class TeacherViewComponent : ViewComponent
{
private readonly UserManager<ApplicationUser> _userManager;
public TeacherViewComponent(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
public async Task<IViewComponentResult> InvokeAsync()
{
List<TeacherViewModel> teachers = new List<TeacherViewModel>();
var items = await _userManager.GetUsersInRoleAsync("Teacher");
foreach (var item in items)
{
teachers.Add(new TeacherViewModel {FatherName=item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });
}
return View(teachers);
}
}
Under Shred Folder Create tree structured directory like this
/Shared/Components/All
/Shared/Components/Teacher
/Shared/Components/Students
Under All Directory , you can create a view which default name is "Default"
@model IEnumerable<StudentManagementSystem.ViewModels.StudentViewModel>
@{
ViewData["Title"] = "Default";
}
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.EnrollmentNo)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Age)
</th>
<th>
@Html.DisplayNameFor(model => model.Birthdate)
</th>
<th>
@Html.DisplayNameFor(model => model.Gender)
</th>
<th>
@Html.DisplayNameFor(model => model.Address)
</th>
<th>
@Html.DisplayNameFor(model => model.FatherName)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.EnrollmentNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Age)
</td>
<td>
@Html.DisplayFor(modelItem => item.Birthdate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Gender)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.DisplayFor(modelItem => item.FatherName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Similarly you can create view to other two views.
Now, If you want to implements tabs view then create a ViewModel Class for tabs
namespace StudentManagementSystem.ViewModels
{
public class UsersTabViewModel
{
public Tab ActiveTab { get; set; }
}
public enum Tab
{
All,
Teachers,
Students
}
}
Now, You can use it in cshtml file like this
@model StudentManagementSystem.ViewModels.UsersTabViewModel
@{
ViewData["Title"] = "Index";
}
<h2>Users Table</h2>
<ul class="nav nav-tabs">
<li role="presentation" class="@(Model.ActiveTab == StudentManagementSystem.ViewModels.Tab.All ? "active" : string.Empty )"><a asp-route-tabname="All" asp-action="SwitchToTabs">All</a></li>
<li role="presentation" class="@(Model.ActiveTab == StudentManagementSystem.ViewModels.Tab.Teachers ? "active" : string.Empty )"><a asp-route-tabname="Teachers" asp-action="SwitchToTabs">Teachers</a></li>
<li role="presentation" class="@(Model.ActiveTab == StudentManagementSystem.ViewModels.Tab.Students ? "active" : string.Empty )"><a asp-route-tabname="Students" asp-action="SwitchToTabs">Students</a></li>
</ul>
@switch (Model.ActiveTab)
{
case StudentManagementSystem.ViewModels.Tab.All:
@await Component.InvokeAsync("All");
break;
case StudentManagementSystem.ViewModels.Tab.Teachers:
@await Component.InvokeAsync("Teacher");
break;
case StudentManagementSystem.ViewModels.Tab.Students:
@await Component.InvokeAsync("Students");
break;
default:
break;
}
Now, The controller section for each route value are
public IActionResult Index(UsersTabViewModel vm)
{
if (vm == null)
{
vm = new UsersTabViewModel
{
ActiveTab = Tab.All
};
}
return View(vm);
}
public IActionResult SwitchToTabs(string tabname)
{
var vm = new UsersTabViewModel();
switch (tabname)
{
case "All":
vm.ActiveTab = Tab.All;
break;
case "Teachers":
vm.ActiveTab = Tab.Teachers;
break;
case "Students":
vm.ActiveTab = Tab.Students;
break;
default:
vm.ActiveTab = Tab.All;
break;
}
return RedirectToAction(nameof(AdminController.Index), vm);
}
What Is Social Media Optimization (SMO)?
ReplyDeleteWHY DIGITAL MARKETING IS IMPORTANT FOR SMALL BUSINESS?
Thanks for sharing this article, it was excellent and very informative. It's really very useful for all the users. I found a lot of informative stuff in your article. Keep it up.
I am so happy to visit this blog and I love to read. Please stay upto date with your blogs, we will visit again to check our your new post.
ReplyDeleteketogenic forums
Thanks, that works - Mobile and web development company in Virginia USA
ReplyDeleteNice Post. Keep sharing more and more web design services
ReplyDeleteweb design company
Awesome Blog Post.
ReplyDeleteThis content is very helpful for selling your old gadgets.
Thank you shring with us.
Get more content visit: sell camcorder
Great Content. It will useful for knowledge seekers. Keep sharing your knowledge through this kind of article.
ReplyDeleteNode JS Course in Chennai
Perl Course in Chennai
Outstanding work author. Knowledgeable enough. We will surely share your work. Anyway, If you are interested and looking for website development you may visit this website.
ReplyDeleteInwizards
Hire Xamarin developer
Hire Blazor developer
Hire ABP,io Developer
ReplyDeleteNice blog! Thanks for sharing this valuable information
Angularjs Training in Bangalore
Angularjs classes in pune
Angularjs Training in hyderabad
Angularjs Training in Gurgaon
Angularjs Training in delhi
This post is so interactive and informative.keep updating more information...
ReplyDeleteArtificial Intelligence Course in Mumbai
Artificial Intelligence Course in Ahmedabad
Artificial Intelligence Course in Kochi
Artificial Intelligence Course in Trivandrum
Artificial Intelligence Course in Kolkata
This is Great Article. You are post informatics blog so keep posting.
ReplyDeleteGoogle 360 Virtual Tour
Top SEO company in Meerut
Top 10 CBSE Schools in Meerut
Satta King Chart Result
Software Development Company India
Satta King Live Result
Meerut Education News Update
Cooking Fever MOD APK
Services at Home
List of Meerut Hospital
ReplyDeleteThis post is so helpful. Keep updating us with more information
Graphic Features
Graphic Design Elements
Web designing institute in Noida
ReplyDeleteWeb designing and development institute in Noida
PHP Training institute in Noida
Thanks for the valuable information and insights you have so provided here... Know What is the NEED for Businesses to Invest in FinTech App.
ReplyDeleteAwesome blog. Thanks for sharing such a worthy information....
ReplyDelete.Net Training in Hyderabad
Dot Net Training Institute in Delhi
Good Post. I like your blog. Thanks for Sharing.
ReplyDeleteVisit us: dot net training
Visit us: Dot Net Online Training Hyderabad
Excellent blog.thanks for sharing such a worthy information....
ReplyDeleteBest Selenium Training Institute in Bangalore
Thanks for sharing this valuable and understanding article with us.
ReplyDeleteFinding SEO Company Surat
then plusply digital is offering the best SEO Services in Surat for
your business website or Online Marketing.
Outstanding work author. Knowledgeable enough.
ReplyDeleteif you want to hire abp.io developer then hire it from inwizards web and app development company
This post is so helpfull and informative.Keep updating with more information...
ReplyDeleteFull Stack Cloud Developer
Full Stack Mobile Developer
This post is so helpfull and informative.keep updating with more information...
ReplyDeleteHacker Interface
Hacking Technology
Most usefull informations!!! Thanks for it.
ReplyDeletePython Course in Chennai
Learn python online
Python Course in Coimbatore
Wonderful Blog post!!! I am more impressed with your data.
ReplyDeleteWhy Pointers are not Used in Java
Why Java Doesn't Support Pointers
Excellent information in this Post. Keep it up. Thanks for sharing Love to read it, Waiting For More new Update and I Already Read your Recent Post its Great Thanks,
ReplyDeleteGST Filing
Income Tax Filing
Nice blog! I really loved reading through this Blog... Thanks for sharing.......
ReplyDeleteHire Blockchain Developers
Excellent article and this helps to enhance your knowledge regarding new things. Waiting for more updates.
ReplyDeleteAngular CSS
Angular Material
Thank You For Sharing informative Post
ReplyDeleteDot Net Developer
Hire.Net Developer
Great post. keep sharing such a worthy information.
ReplyDeletecontent writing course in chennai
online content writing course
Informative blog very useful , thanks for sharing this
ReplyDeleteCustom WordPress Development Services
Is your child using mobile all the day not learning a thing about it!
ReplyDeleteWe bring fun learning to your child's fingertips.
This visual learning app is created for kids with a fun factor. It allows you to learn complex topics quickly and retain a lot of useful and valuable information for a more extended time.
With the Multiply app, your kid gets a secure & free environment of learning while having fun.
Included with knowledgeable infographic images, carousels, and reels, the Multiply App is one of the unique mobile apps that your child will come across ever.
Multiply app has various learning categories that allow your child to learn almost everything they need to know.
If your kid spends most of their time on the screen, why not make it productive for them!
Give your child a fun & engaging way to learn with Multiply App.
Get it on Google Play: https://bit.ly/34SVQFg
Need the answer for the questionWhich Software Course Is Best For Freshers?? Get this into the blog with Infycle Technologies for having the top interview questions and answers! Call 7504633633 or 7502633633 for having the best software development courses!
ReplyDeleteUsing ViewComponent, i want to redirect to the page i have created in View folder , is it possible?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteAt APTRON NOIDA, you can enroll in a range of .NET Training in Noida, including beginner, intermediate, and advanced levels. Whether you're looking to learn the basics of .NET programming or want to enhance your existing skills, the institute has a program that's suitable for you. APTRON NOIDA's .NET training courses cover a wide range of topics, including .NET framework, C#, ASP.NET, SQL Server, LINQ, WPF, and more. With a comprehensive curriculum and hands-on training, students gain practical experience and develop the necessary skills to excel in their careers.
ReplyDeleteGreat post.
ReplyDeleteFull stack classes in Pune
Thanks for sharing this informative article on How to use Tabs in ASP.NET CORE. If you want to ASP.Net Core Development Company for your project. Please visit us.
ReplyDeleteIt is a significant and useful article for us. inventory management software
ReplyDeleteThanks for sharing this excellent post. Angular Training In Pune
ReplyDeleteThanks for sharing this informative post.
ReplyDeleteSQL Classes in Pune
Your explanation of the controller actions for handling tab switching is clear and concise, and it effectively ties together the entire functionality. The introduction of a View Model for tabs is a smart move, general paper questions simplifying the handling of active tabs and making the code cleaner and more readable. The integration of this View Model into the Razor view is seamless and enhances the overall user experience.
ReplyDeleteasdfsf
ReplyDeleteThank-you so much sir for providing this wonderful knowledge regarding asp.net
ReplyDelete