I am brand new to this I have a website in which I have a Projectcontroller an three views in it and I want to show all of the view pages details into one detail page so when try to click & see detail of project that detail link should include all other view page details as read only view right now I only see details for one page which belongs to project controller. How do I import those views table data details into the project controller detail page. Do I need to create detail pages for those two views as well?
ProjectController code
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 SNAPAIS.Models;
using SNAPAIS.Utils;
namespace SNAPAIS.Controllers
{
public class ProjectsController : BaseController
{
private AISEntities db = new AISEntities();
// GET: Projects
public ActionResult Index(int id)
{
var projects = db.Projects.Where(p => p.Contract.Id == id).Include(x=> x.Contract).ToList();
ViewBag.ContractId = id;
return View(projects);
}
// GET: Projects/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Project project = db.Projects.Where(x=> x.Id==id).SingleOrDefault();
if (project == null)
{
return HttpNotFound();
}
return View(project);
}
// GET: Projects/Create
public ActionResult Create(int contractId)
{
Project project = new Project();
project.Id = 0;
project.ContractId = contractId;
return View(project);
}
// POST: Projects/Create
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,ContractId,ProjectName,ProjectManager,MODNumber,POP,CurrentYearOfPOP,AwardAmount,FundingBaseYear,OY1,OY2,OY3,OY4,CustomerName,CustomerAddress,CustOfficerName,CustSpeciAddress,CORName,CORAddress,TPOCName,TPOCAddress,IsWDC,IsIDIQ,InvoiceInfo,InvoicePeriod,Schedule,InvoiceSubNote")] Project project)
{
if (ModelState.IsValid)
{
project.CreatedDate = LoginInfo.CurrentDate();
project.CreatedBy = LoginInfo.CurrentUser();
db.Projects.Add(project);
db.SaveChanges();
return RedirectToAction("Accounting", new { projectId = project.Id });
}
return View(project);
}
public ActionResult Accounting(int projectId)
{
Accounting accounting = new Accounting();
accounting.Id = 0;
accounting.ProjectId = projectId;
return View(accounting);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Accounting([Bind(Include = "Id,ProjectId,NewCPProjectNo,ChargeLevelTimesheet,PLCRate,BillingRate")] Accounting accounting)
{
if (ModelState.IsValid)
{
accounting.CreatedBy = LoginInfo.CurrentUser();
accounting.CreatedDate = LoginInfo.CurrentDate();
Project project = db.Projects.Where(x => x.Id == accounting.ProjectId).Single();
db.Accountings.Add(accounting);
db.SaveChanges();
return RedirectToAction("HR", new { projectId = project.Id });
}
return View(accounting);
}
public ActionResult HR(int projectId)
{
HR hR = new HR();
hR.Id = 0;
hR.ProjectId = projectId;
return View(hR);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult HR([Bind(Include = "Id,ProjectId,EmployeeName,EmployeeType,Position,LabourCategory,DOB,Address,StartDate,Organization,CPProjectCode,CSHS,PayRate,AcualRate,DUNS,UniqueId,BillingRate,ReportingManager,TimesheetApprover,EmailAddress")] HR hR)
{
if (ModelState.IsValid)
{
hR.CreatedBy = LoginInfo.CurrentUser();
hR.CreatedDate = LoginInfo.CurrentDate();
Project project = db.Projects.Where(x => x.Id == hR.ProjectId).Single();
db.HRs.Add(hR);
db.SaveChanges();
return RedirectToAction("Index", new { id = project.ContractId });
}
return View(hR);
}
// GET: Projects/Edit/5
public ActionResult Edit(int? projectId)
{
if (projectId == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Project project = db.Projects.Find(projectId);
if (project == null)
{
return HttpNotFound();
}
return View(project);
}
// POST: Projects/Edit/5
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Id,ContractId,ProjectName,ProjectManager,MODNumber,POP,CurrentYearOfPOP,AwardAmount,FundingBaseYear,OY1,OY2,OY3,OY4,CustomerName,CustomerAddress,CustOfficerName,CustSpeciAddress,CORName,CORAddress,TPOCName,TPOCAddress,IsWDC,IsIDIQ,InvoiceInfo,InvoicePeriod,Schedule,InvoiceSubNote,CreatedBy,CreatedDate")] Project project)
{
if (ModelState.IsValid)
{
db.Entry(project).Entity.ModifiedBy = LoginInfo.CurrentUser();
db.Entry(project).Entity.ModifiedDate = LoginInfo.CurrentDate();
db.Entry(project).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("AccountingEdit", new { projectId = project.Id});
}
return View(project);
}
// GET: Accounting/Edit/5
public ActionResult AccountingEdit(int? projectId)
{
if (projectId == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Accounting accounting = db.Accountings.Where(x =>x.ProjectId == projectId).SingleOrDefault();
if (accounting == null)
{
return HttpNotFound();
}
return View(accounting);
}
// POST: Accounting/Edit/5
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AccountingEdit([Bind(Include = "Id,ProjectId,NewCPProjectNo,ChargeLevelTimesheet,PLCRate,BillingRate,CreatedBy,CreatedDate")] Accounting accounting)
{
if (ModelState.IsValid)
{
db.Entry(accounting).Entity.ModifiedBy = LoginInfo.CurrentUser();
db.Entry(accounting).Entity.ModifiedDate = LoginInfo.CurrentDate();
db.Entry(accounting).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("HREdit", new { projectId = accounting.ProjectId });
}
return View(accounting);
}
// GET: HR/Edit/5
public ActionResult HREdit(int? projectId)
{
if (projectId == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
HR hR = db.HRs.Where(x=> x.ProjectId== projectId).SingleOrDefault();
if (hR == null)
{
return HttpNotFound();
}
return View(hR);
}
// POST: HR/Edit/5
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult HREdit([Bind(Include = "Id,ProjectId,EmployeeName,EmployeeType,Position,LabourCategory,DOB,Address,StartDate,Organization,CPProjectCode,CSHS,PayRate,AcualRate,DUNS,UniqueId,BillingRate,ReportingManager,TimesheetApprover,EmailAddress,CreatedBy,CreatedDate")] HR hR)
{
if (ModelState.IsValid)
{
db.Entry(hR).Entity.ModifiedBy = LoginInfo.CurrentUser();
db.Entry(hR).Entity.ModifiedDate = LoginInfo.CurrentDate();
db.Entry(hR).State = EntityState.Modified;
db.SaveChanges();
Project project = db.Projects.Find(hR.ProjectId);
return RedirectToAction("Index", new { id = project.ContractId });
}
return View(hR);
}
// GET: Projects/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Project project = db.Projects.Find(id);
if (project == null)
{
return HttpNotFound();
}
return View(project);
}
// POST: Projects/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Project project = db.Projects.Find(id);
db.Projects.Remove(project);
db.SaveChanges();
return RedirectToAction("Index", new { id = project.ContractId });
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
Detail page code
@model SNAPAIS.Models.Project
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Details</h2>
<div >
<div >
<h3 >Project details</h3>
</div>
<div >
<dl >
<dt>
@Html.DisplayNameFor(model => model.Contract.ContractName)
</dt>
<dd>
@Html.DisplayFor(model => model.Contract.ContractName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.ProjectName)
</dt>
<dd>
@Html.DisplayFor(model => model.ProjectName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.ProjectManager)
</dt>
<dd>
@Html.DisplayFor(model => model.ProjectManager)
</dd>
<dt>
@Html.DisplayNameFor(model => model.MODNumber)
</dt>
<dd>
@Html.DisplayFor(model => model.MODNumber)
</dd>
<dt>
@Html.DisplayNameFor(model => model.POP)
</dt>
<dd>
@Html.DisplayFor(model => model.POP)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CurrentYearOfPOP)
</dt>
<dd>
@Html.DisplayFor(model => model.CurrentYearOfPOP)
</dd>
<dt>
@Html.DisplayNameFor(model => model.AwardAmount)
</dt>
<dd>
@Html.DisplayFor(model => model.AwardAmount)
</dd>
<dt>
@Html.DisplayNameFor(model => model.FundingBaseYear)
</dt>
<dd>
@Html.DisplayFor(model => model.FundingBaseYear)
</dd>
<dt>
@Html.DisplayNameFor(model => model.OY1)
</dt>
<dd>
@Html.DisplayFor(model => model.OY1)
</dd>
<dt>
@Html.DisplayNameFor(model => model.OY2)
</dt>
<dd>
@Html.DisplayFor(model => model.OY2)
</dd>
<dt>
@Html.DisplayNameFor(model => model.OY3)
</dt>
<dd>
@Html.DisplayFor(model => model.OY3)
</dd>
<dt>
@Html.DisplayNameFor(model => model.OY4)
</dt>
<dd>
@Html.DisplayFor(model => model.OY4)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CustomerName)
</dt>
<dd>
@Html.DisplayFor(model => model.CustomerName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CustomerAddress)
</dt>
<dd>
@Html.DisplayFor(model => model.CustomerAddress)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CustOfficerName)
</dt>
<dd>
@Html.DisplayFor(model => model.CustOfficerName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CustSpeciAddress)
</dt>
<dd>
@Html.DisplayFor(model => model.CustSpeciAddress)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CORName)
</dt>
<dd>
@Html.DisplayFor(model => model.CORName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CORAddress)
</dt>
<dd>
@Html.DisplayFor(model => model.CORAddress)
</dd>
<dt>
@Html.DisplayNameFor(model => model.TPOCName)
</dt>
<dd>
@Html.DisplayFor(model => model.TPOCName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.TPOCAddress)
</dt>
<dd>
@Html.DisplayFor(model => model.TPOCAddress)
</dd>
<dt>
@Html.DisplayNameFor(model => model.IsWDC)
</dt>
<dd>
@Html.DisplayFor(model => model.IsWDC)
</dd>
<dt>
@Html.DisplayNameFor(model => model.IsIDIQ)
</dt>
<dd>
@Html.DisplayFor(model => model.IsIDIQ)
</dd>
<dt>
@Html.DisplayNameFor(model => model.InvoiceInfo)
</dt>
<dd>
@Html.DisplayFor(model => model.InvoiceInfo)
</dd>
<dt>
@Html.DisplayNameFor(model => model.InvoicePeriod)
</dt>
<dd>
@Html.DisplayFor(model => model.InvoicePeriod)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Schedule)
</dt>
<dd>
@Html.DisplayFor(model => model.Schedule)
</dd>
<dt>
@Html.DisplayNameFor(model => model.InvoiceSubNote)
</dt>
<dd>
@Html.DisplayFor(model => model.InvoiceSubNote)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CreatedDate)
</dt>
<dd>
@Html.DisplayFor(model => model.CreatedDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CreatedBy)
</dt>
<dd>
@Html.DisplayFor(model => model.CreatedBy)
</dd>
<dt>
@Html.DisplayNameFor(model => model.ModifiedDate)
</dt>
<dd>
@Html.DisplayFor(model => model.ModifiedDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.ModifiedBy)
</dt>
<dd>
@Html.DisplayFor(model => model.ModifiedBy)
</dd>
</dl>
</div>
<div >
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
@Html.ActionLink("Back to List", "Index")
</p>
</div>
</div>
CodePudding user response:
You can create another model that contains every existing models as properties.
public class AnotherModel
{
public Accounting Accounting {get; set;}
public Project Project {get; set;}
}
Then you have to get data from your data sources and put them together in another View with model @model SNAPAIS.Models.AnotherModel
.