I am a total beginner on .NET and MVC5. I have created -using scaffolds-, all the catalogs sets of views/controllers/models for my web app. They work just fine, each one on its corresponding menu.
But want I want to do is to have a single view with a Twitter Bootstrap's tab panel, in which one tab will represent a catalog of my app.
I have been reading this article, which as far as I can get with my limited knowledge on the matter, show 6 ways to do what I am looking to do.
This would be my main controller, all other controllers depend on it:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using TestSite.Models;
namespace TestSite.Controllers
{
public class ClientsController : Controller
{
private TestSiteDBContext db = new TestSiteDBContext();
// GET: Clients
public ActionResult Index()
{
return View(db.Clients.ToList());
}
// GET: Clients/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Client client = db.Clients.Find(id);
if (client == null)
{
return HttpNotFound();
}
return View(client);
}
// GET: Clients/Create
public ActionResult Create()
{
return View();
}
// POST: Clients/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,name,logoName,status,creationDate")] Client client)
{
if (ModelState.IsValid)
{
db.Clients.Add(client);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(client);
}
// GET: Clients/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Client client = db.Clients.Find(id);
if (client == null)
{
return HttpNotFound();
}
return View(client);
}
// POST: Clients/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "ID,name,logoName,status,creationDate")] Client client)
{
if (ModelState.IsValid)
{
db.Entry(client).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(client);
}
// GET: Clients/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Client client = db.Clients.Find(id);
if (client == null)
{
return HttpNotFound();
}
return View(client);
}
// POST: Clients/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Client client = db.Clients.Find(id);
db.Clients.Remove(client);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
And other controllers such as departments, should be showing their contents inside the clients' show views:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using TestSite.Models;
namespace TestSite.Controllers
{
public class DepartmentsController : Controller
{
private TestSiteDBContext db = new TestSiteDBContext();
// GET: Departments
public ActionResult Index()
{
return View(db.Departments.ToList());
}
// GET: Departments/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Department department = db.Departments.Find(id);
if (department == null)
{
return HttpNotFound();
}
return View(department);
}
// GET: Departments/Create
public ActionResult Create()
{
ViewBag.BranchList = new SelectList(db.Branches, "ID", "name");
return View();
}
// POST: Departments/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "id,name,branchId,creationDate")] Department department)
{
if (ModelState.IsValid)
{
db.Departments.Add(department);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(department);
}
// GET: Departments/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Department department = db.Departments.Find(id);
if (department == null)
{
return HttpNotFound();
}
return View(department);
}
// POST: Departments/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "id,name,branchId,creationDate")] Department department)
{
if (ModelState.IsValid)
{
db.Entry(department).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(department);
}
// GET: Departments/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Department department = db.Departments.Find(id);
if (department == null)
{
return HttpNotFound();
}
return View(department);
}
// POST: Departments/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Department department = db.Departments.Find(id);
db.Departments.Remove(department);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
I would like to ask you for advice on which one of those 6 methods should I focus first. Thanks!