如何为一个详细信息页面中的所有视图选项卡创建只读视图?

How do I make a read only view for all view tabs in one detail page?

我是全新的,我有一个网站,其中有一个项目控制器,其中有三个视图,我想将所有视图页面的详细信息显示到一个详细信息页面中,因此当尝试单击并查看详细信息时项目详细信息 link 应该包括所有其他视图页面详细信息作为只读视图,现在我只看到属于项目控制器的一页的详细信息。如何将这些视图 table 数据详细信息导入项目控制器详细信息页面。我是否也需要为这两个视图创建详细信息页面?

项目控制器代码

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);
        }
    }
}

详情页面代码

@model SNAPAIS.Models.Project

@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Details</h2>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">Project details</h3>
    </div>

    <div class="panel-body">
        <dl class="dl-horizontal">
            <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 class="panel-footer">
        <p>
            @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
            @Html.ActionLink("Back to List", "Index")
        </p>
    </div>
</div>

您可以创建另一个模型,其中包含每个现有模型作为属性。

public class AnotherModel
{
  public Accounting Accounting {get; set;}
  public Project Project {get; set;}
}

然后您必须从您的数据源中获取数据并将它们放在另一个具有模型 @model SNAPAIS.Models.AnotherModel 的视图中。