我正在研究Web應用程序的設計。該應用程序最初並不是由我編碼的,並且我在嘗試設計時儘量不要修改任何控制器或模型。將信息從模型拉入局部視圖
此刻,應用程序是一個標題,應該顯示您正在查看的項目的名稱和項目的完成日期。此標題是佈局調用的局部視圖,也是局部視圖。因爲標題是一個單獨的視圖,所以在項目詳細信息視圖中,我很難抽出這些信息。
我試着給控制器添加一個@model引用給Header,但得到了一個錯誤,我傳入的錯誤類型(請參閱下面的錯誤)。
我也嘗試將模型傳遞給調用標頭的Layout視圖中的@ Html.Partial調用(也是this)。一般來說一切我曾嘗試讓我這個錯誤:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[OST.Pride.Business.Models.Project]', but this dictionary requires a model item of type 'OST.Pride.Web.Models.AdminProjectUserEdit'.
我不能隨便動頭項目詳細信息視圖,因爲頭是整個應用程序的佈局的一部分。我會很感激任何人在這方面的幫助,我已經停留了一段時間。
頭被稱爲佈局
<header id="main-header">
@Html.Partial("LayoutTemplates/Header")
</header>
標題:
<div class="navbar" style="padding-top:15px;">
<div class="navbar-inner">
<div class="container" style="width:auto;">
<div class="project-navbar">
<h3><ul class="nav pull-left">Customer: TEST </ul></h3>
<h3><ul class="nav" style="padding-left:40%;">Project: //This is where the project name needs to be//</ul></h3>
<h3><ul class="nav pull-right" align="center">Project Completion Date: //Again, I need to pull the completion date here// </ul></h3>
</div>
</div>
</div>
</div>
控制器的方法
public ActionResult Details(int? projectid, int? ProjectID, int? projectuserid) // based on the project id, populates the view with the roles, project users, and the roles for the screen.
{
var model = new Models.AdminProjectUserEdit();
model.Project = storeDB.Projects.Find(ProjectID);
model.Users = storeDB.Users.ToList();
model.Surveys = storeDB.Surveys.Include("SurveyType").ToList();
model.ProjectUsers = storeDB.ProjectUsers.Include("Project").Include("User").Where(x => x.ProjectID == projectid).ToList();
return View(model);
}
好的,謝謝你的幫助。我非常確定這正是我需要的,我只需要弄清楚如何正確實施這個項目。我會及時通知你的。 – LemonFlip 2012-07-06 17:55:01
projectID參數是一個路由,所以我現在要開始調整它。如果您想相應地更新您的答案,請隨時免費,否則我仍計劃在完成並運行後再對其進行標記。再次感謝。 – LemonFlip 2012-07-06 18:00:02
答覆已更新。 – 2012-07-06 18:24:22