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 }); }
Introduction
In MVC index method is the default method in application
route file. Means you can say Index is the first running action method. Here
this example show how to change default method means
Index to another method.
Follow some steps for changing Default method
Step-1: Create a new action method in the Home controller
class
Like
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication3.Controllers
{
public class HomeController : Controller
{
//
// GET:
/Home/
public ActionResult Index()
{
return View();
}
public string detail()
{
return "hello";
}
}
}
This example take two method first one is Index ( Default
method) and another one is detail method . If you want to set default method is
detail then you would go RouteConfig.cs file.
Step-2: Open
RouteConfig.cs file which is inside in App_Start folder.
Step-3: Change action
value in RouteConfig.cs file
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action
= "detail", id = UrlParameter.Optional }
);
}
Step-4: Assign second action method name (detail) to action
value in RegisterRoutes method (which is mentioned above).
Step-5 : Save your Application and run.
Comments
Post a Comment