Вы находитесь на странице: 1из 11

home controller index

...................
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm())
{
<h2>Main Index</h2>
<div>
<table>
<tr>
<td><input type="submit" value="Main Index" class="btn btn-primary"
name="btn" /></td>
<td><input type="submit" value="Admin Index" class="btn btn-danger"
name="btn" /></td>
<td><input type="submit" value="Manager Index" class="btn btn-
success" name="btn" /></td>
<td><input type="submit" value="HR Index" class="btn btn-info"
name="btn" /></td>
<td><input type="submit" value="Employee Index" class="btn btn-
warning" name="btn" /></td>
</tr>
</table>
</div>
<table>
<tr>
<td>@Html.ActionLink("Go to Main Index", "Index", "Home", new { Area =
"" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Manager Index", "Index", "Home", new { Area
= "Manager" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to HR Index", "Index", "Home", new { area =
"HR" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Employee Index", "Index", "Home", new
{ area = "Employee" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Admin Index", "Index", "Home", new { area =
"Admin" }, new { })</td>
</tr>
</table>
}
..................................
home controller

.......................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AreaExample.Controllers
{
public class HomeController : Controller
{
// GET: Home
[HttpGet]
public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Index(string btn)
{
if(btn== "Main Index")
{
return RedirectToAction("Index", "Home", new { area = "" });
}
else if(btn== "Admin Index")
{
return RedirectToAction("Index", "Home", new { area = "Admin" });
}
else if (btn == "Manager Index")
{
return RedirectToAction("Index", "Home", new { area = "Manager" });
}
else if (btn == "HR Index")
{
return RedirectToAction("Index", "Home", new { area = "HR" });
}
else if (btn == "Employee Index")
{
return RedirectToAction("Index", "Home", new { area =
"Employee" });
}
return View();
}
}
}
.....................................
IReposite
....................

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AreaExample.IRepository
{
public interface IReposite
{
// 1 Main

// 1.1 This method is used to insert emp data into a database table called
MainTable...!
void InsertMainEmp();

// 2 Admin
// 2.1 This method is used to insert emp data into a database table called
MainTable...!
void InsertAdminEmp();

// 3 Manager
// 3.1 This method is used to insert emp data into a database table called
MainTable...!
void InsertManagerEmp();

// 4 HR
// 4.1 This method is used to insert emp data into a database table called
MainTable...!
void InsertHREmp();

// 5 Employee
// 5.1 This method is used to insert emp data into a database table called
MainTable...!
void InsertEmployeeEmp();
}
}
.............................................................
ManagerAreaRegistration
.....................................

using System.Web.Mvc;

namespace AreaExample.Areas.Manager
{
public class ManagerAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Manager";
}
}

public override void RegisterArea(AreaRegistrationContext context)


{
context.MapRoute(
"Manager_default",
"Manager/{controller}/{action}/{id}",
new { Controller = "Home", action = "Index", id =
UrlParameter.Optional }
);
}
}
}
..........................

@{
ViewBag.Title = "Index";
}

@using (Html.BeginForm())
{
<h2>Manager Index</h2>
<div>
<table>
<tr>
<td><input type="submit" value="Main Index" class="btn btn-primary"
name="btn" /></td>
<td><input type="submit" value="Admin Index" class="btn btn-danger"
name="btn" /></td>
<td><input type="submit" value="Manager Index" class="btn btn-
success" name="btn" /></td>
<td><input type="submit" value="HR Index" class="btn btn-info"
name="btn" /></td>
<td><input type="submit" value="Employee Index" class="btn btn-
warning" name="btn" /></td>
</tr>
</table>
</div>
<table>
<tr>
<td>@Html.ActionLink("Go to Main Index", "Index", "Home", new { Area =
"" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Manager Index", "Index", "Home", new { Area
= "Manager" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to HR Index", "Index", "Home", new { area =
"HR" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Employee Index", "Index", "Home", new
{ area = "Employee" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Admin Index", "Index", "Home", new { area =
"Admin" }, new { })</td>
</tr>
</table>
}
....................................................................
HRAreaRegistration
.................
using System.Web.Mvc;

namespace AreaExample.Areas.HR
{
public class HRAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "HR";
}
}

public override void RegisterArea(AreaRegistrationContext context)


{
context.MapRoute(
"HR_default",
"HR/{controller}/{action}/{id}",
new { Controller = "Home", action = "Index", id =
UrlParameter.Optional }
);
}
}
}
...............................

@{
ViewBag.Title = "Index";
}

@using (Html.BeginForm())
{
<h2>HR Index</h2>
<div>
<table>
<tr>
<td><input type="submit" value="Main Index" class="btn btn-primary"
name="btn" /></td>
<td><input type="submit" value="Admin Index" class="btn btn-danger"
name="btn" /></td>
<td><input type="submit" value="Manager Index" class="btn btn-
success" name="btn" /></td>
<td><input type="submit" value="HR Index" class="btn btn-info"
name="btn" /></td>
<td><input type="submit" value="Employee Index" class="btn btn-
warning" name="btn" /></td>
</tr>
</table>
</div>
<table>
<tr>
<td>@Html.ActionLink("Go to Main Index", "Index", "Home", new { Area =
"" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Manager Index", "Index", "Home", new { Area
= "Manager" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to HR Index", "Index", "Home", new { area =
"HR" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Employee Index", "Index", "Home", new
{ area = "Employee" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Admin Index", "Index", "Home", new { area =
"Admin" }, new { })</td>
</tr>
</table>
}
................................................................
EmployeeAreaRegistration
............................
using System.Web.Mvc;
namespace AreaExample.Areas.Employee
{
public class EmployeeAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Employee";
}
}

public override void RegisterArea(AreaRegistrationContext context)


{
context.MapRoute(
"Employee_default",
"Employee/{controller}/{action}/{id}",
new { Controller = "Home", action = "Index", id =
UrlParameter.Optional }
);
}
}
}
...............

@{
ViewBag.Title = "Index";
}

@using (Html.BeginForm())
{
<h2>Employee Index</h2>
<div>
<table>
<tr>
<td><input type="submit" value="Main Index" class="btn btn-primary"
name="btn" /></td>
<td><input type="submit" value="Admin Index" class="btn btn-danger"
name="btn" /></td>
<td><input type="submit" value="Manager Index" class="btn btn-
success" name="btn" /></td>
<td><input type="submit" value="HR Index" class="btn btn-info"
name="btn" /></td>
<td><input type="submit" value="Employee Index" class="btn btn-
warning" name="btn" /></td>
</tr>
</table>
</div>
<table>
<tr>
<td>@Html.ActionLink("Go to Main Index", "Index", "Home", new { Area =
"" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Manager Index", "Index", "Home", new { Area
= "Manager" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to HR Index", "Index", "Home", new { area =
"HR" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Employee Index", "Index", "Home", new
{ area = "Employee" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Admin Index", "Index", "Home", new { area =
"Admin" }, new { })</td>
</tr>
</table>
}
................
AdminAreaRegistration
....................
using System.Web.Mvc;

namespace AreaExample.Areas.Admin
{
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}

public override void RegisterArea(AreaRegistrationContext context)


{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new {Controller="Home", action = "Index", id =
UrlParameter.Optional }
);
}
}
}
.............

@{
ViewBag.Title = "Index";
}

@using (Html.BeginForm())
{
<h2>Admin Index</h2>
<div>
<table>
<tr>
<td><input type="submit" value="Main Index" class="btn btn-primary"
name="btn" /></td>
<td><input type="submit" value="Admin Index" class="btn btn-danger"
name="btn" /></td>
<td><input type="submit" value="Manager Index" class="btn btn-
success" name="btn" /></td>
<td><input type="submit" value="HR Index" class="btn btn-info"
name="btn" /></td>
<td><input type="submit" value="Employee Index" class="btn btn-
warning" name="btn" /></td>
</tr>
</table>
</div>
<table>
<tr>
<td>@Html.ActionLink("Go to Main Index", "Index", "Home", new { Area =
"" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Manager Index", "Index", "Home", new { Area
= "Manager" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to HR Index", "Index", "Home", new { area =
"HR" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Employee Index", "Index", "Home", new
{ area = "Employee" }, new { })</td>
</tr>
<tr>
<td>@Html.ActionLink("Go to Admin Index", "Index", "Home", new { area =
"Admin" }, new { })</td>
</tr>
</table>
}
.............................................................................
Admin/Home

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AreaExample.Areas.Admin.Controllers
{
public class HomeController : Controller
{
// GET: Admin/Home
[HttpGet]
public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Index(string btn)
{
if (btn == "Main Index")
{
return RedirectToAction("Index", "Home", new { area = "" });
}
else if (btn == "Admin Index")
{
return RedirectToAction("Index", "Home", new { area = "Admin" });
}
else if (btn == "Manager Index")
{
return RedirectToAction("Index", "Home", new { area = "Manager" });
}
else if (btn == "HR Index")
{
return RedirectToAction("Index", "Home", new { area = "HR" });
}
else if (btn == "Employee Index")
{
return RedirectToAction("Index", "Home", new { area =
"Employee" });
}
return View();
}
}
}
................................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AreaExample.Areas.Employee.Controllers
{
public class HomeController : Controller
{
// GET: Employee/Home
[HttpGet]
public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Index(string btn)
{
if (btn == "Main Index")
{
return RedirectToAction("Index", "Home", new { area = "" });
}
else if (btn == "Admin Index")
{
return RedirectToAction("Index", "Home", new { area = "Admin" });
}
else if (btn == "Manager Index")
{
return RedirectToAction("Index", "Home", new { area = "Manager" });
}
else if (btn == "HR Index")
{
return RedirectToAction("Index", "Home", new { area = "HR" });
}
else if (btn == "Employee Index")
{
return RedirectToAction("Index", "Home", new { area =
"Employee" });
}
return View();
}
}
}
.................................................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AreaExample.Areas.HR.Controllers
{
public class HomeController : Controller
{
// GET: HR/Home
[HttpGet]
public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Index(string btn)
{
if (btn == "Main Index")
{
return RedirectToAction("Index", "Home", new { area = "" });
}
else if (btn == "Admin Index")
{
return RedirectToAction("Index", "Home", new { area = "Admin" });
}
else if (btn == "Manager Index")
{
return RedirectToAction("Index", "Home", new { area = "Manager" });
}
else if (btn == "HR Index")
{
return RedirectToAction("Index", "Home", new { area = "HR" });
}
else if (btn == "Employee Index")
{
return RedirectToAction("Index", "Home", new { area =
"Employee" });
}
return View();
}
}
}
........................................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AreaExample.Areas.Manager.Controllers
{
public class HomeController : Controller
{
// GET: Manager/Home
[HttpGet]
public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Index(string btn)
{
if (btn == "Main Index")
{
return RedirectToAction("Index", "Home", new { area = "" });
}
else if (btn == "Admin Index")
{
return RedirectToAction("Index", "Home", new { area = "Admin" });
}
else if (btn == "Manager Index")
{
return RedirectToAction("Index", "Home", new { area = "Manager" });
}
else if (btn == "HR Index")
{
return RedirectToAction("Index", "Home", new { area = "HR" });
}
else if (btn == "Employee Index")
{
return RedirectToAction("Index", "Home", new { area =
"Employee" });
}
return View();
}
}
}

Вам также может понравиться