我有一個示範課程,組件,子組件和評估:插入值MVC 4
public class Course
{
public virtual int CourseId { get; set; }
(...)
public virtual List<Component> Components { get; set; }
public virtual List<UserCourse> Users { get; set; }
}
public class Component
{
public virtual int ComponentId { get; set; }
public virtual string Type { get; set; }
public virtual string Name { get; set; }
public virtual Course Course { get; set; }
public virtual List<Subcomponent> Subcomponents { get; set; }
}
public class Subcomponent
{
public virtual int SubcomponentId { get; set; }
public virtual int ComponentId { get; set; }
public virtual string TypeSub { get; set; }
public virtual string NameSub { get; set; }
(...)
public virtual int ParentId { get; set; }
public virtual Subcomponent Parent { get; set; }
public virtual List<Subcomponent> Childs { get; set; }
public virtual Component Component { get; set; }
}
public class Evaluation
{
public virtual int EvaluationId { get; set; }
public virtual int ComponentId { get; set; }
public virtual Component Component { get; set; }
public virtual int UserCourseId { get; set; }
public virtual UserCourse User { get; set; }
public virtual int Grade { get; set; }
}
我需要給一年級到每個子組件(或組件,如果組件不有子組件)給每個用戶。 首先我有一個觀點,即顯示了用戶和已經給出的成績,像一個指標:
@model SGP.Models.Course
<table>
<tr>
<th>
Users
</th>
<th>
Grades
</th>
</tr>
@foreach (var x in Model.Users)
{
<tr>
<td>
@Html.DisplayFor(modelItem => x.User.UserName)
</td>
@foreach (var y in x.Evaluation)
{
<td>
<table>
<tr>
<td>
<b>@Html.DisplayFor(modelItem => y.Component.NameComp)</b>
</td>
</tr>
<tr>
<td>
@Html.DisplayFor(modelItem => y.Grade)
</td>
</tr>
</table>
</td>
}
<td>
@Html.ActionLink("Give grade", "Comps", "Evaluation", new { id = x.UserCourseId }, null)
</td>
</tr>
}
</table>
然後,當按下「給品位」,我有一個搜索框,選擇組件至極的品位將得到。 搜索將給出該組件的子組件列表。每個組件可以有一個或多個子組件,因此該組件的最終等級是子組件等級的平均值。 子組件的視圖:
@model SGP.Models.Component
<table>
<tr>
<th>
@Html.DisplayFor(model => model.NameComp)
</th>
<th>
Grade
</th>
</tr>
@foreach (var item in Model.Subcomponents) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.NameSub)
</td>
<td>
???????
</td>
</tr>
}
</table>
但這個觀點我需要得到預先選擇的UserCourseId並給了一個檔次,以在選定的子用戶。我怎樣才能做到這一點? 感謝
編輯: 給予等級:
@using (Html.BeginForm("ListaSubs", "Evaluation", FormMethod.Post))
{
<table>
<tr>
<th>
@Html.TextBox("text")
</th>
<td>
<input type="submit" id="ButtonSearch" value="Search" />
</td>
</tr>
</table>
}
和控制器:
[HttpPost, ActionName("ListaSubs")]
public ActionResult ListaSubs(string text)
{
var util = (db.Subcomponents.Where(m =>
m.ComponentId.Equals(text)));
return View("view", util);
}
什麼是「給級」視圖的樣子和它是如何顯示的? – Steve
@Steve現在的問題 – dasdasd