因此,我有一個ReviewsController和一個ActionResults,它在我的數據庫中查詢我的表格,並在不同視圖中返回它們,例如在另一個視圖中呈現視圖(不是局部視圖)
在ReviewsController
public ActionResult StudentWellnessReviews()
{
using (var context = new SizaFakeEntities())
{
var userreview = context.Reviews.SqlQuery("select * from dbo.Review where WellnessService='Student Wellness Service'").ToList();
return View(userreview);
}
}
而且
public ActionResult HAICUReviews()
{
using (var context = new SizaFakeEntities())
{
var userreview = context.Reviews.SqlQuery("select * from dbo.Review where WellnessService='HAICU' ").ToList();
return View(userreview);
}
}
StudentWellnessReviews查看:
<table class="table text-center width:50%">
<tr>
<td>
@Html.ActionLink("Make Review", "Create", "Reviews", null, new { @class = "btn btn-success btn-sm" })
@Html.ActionLink("Edit Posted Reviews", "ReviewEdit", "Reviews", null, new { @class = "btn btn-info btn-sm" })
</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<h5>Username</h5>
</td>
<td>
<p><div align="left">@Html.DisplayFor(modelItem => item.Username)</div></p>
</td>
</tr>
<tr>
<td>
<h5>Wellness Service</h5>
</td>
<td>
<p><div align="left">@Html.DisplayFor(modelItem => item.WellnessService)</div></p>
</td>
</tr>
<tr>
<td>
<h5>Rating</h5>
</td>
<td>
<p><div align="left">@Html.DisplayFor(modelItem => item.Rating)</div></p>
</td>
</tr>
<tr>
<td>
<h5>Feedback</h5>
</td>
<td>
<p><div align="left"> @Html.DisplayFor(modelItem => item.Feedback)</div></p>
</td>
</tr>
<tr><td colspan="2"><hr class="active" /></td></tr>
}
</table>
HAICUReviews查看:
<table class="table text-center width:50%">
<tr>
<td>
@Html.ActionLink("Make Review", "Create", "Reviews", null, new { @class = "btn btn-success btn-sm" })
@Html.ActionLink("Edit Posted Reviews", "ReviewEdit", "Reviews", null, new { @class = "btn btn-info btn-sm" })
</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<h5>Username</h5>
</td>
<td>
<p><div align="left">@Html.DisplayFor(modelItem => item.Username)</div></p>
</td>
</tr>
<tr>
<td>
<h5>Wellness Service</h5>
</td>
<td>
<p><div align="left">@Html.DisplayFor(modelItem => item.WellnessService)</div></p>
</td>
</tr>
<tr>
<td>
<h5>Rating</h5>
</td>
<td>
<p><div align="left">@Html.DisplayFor(modelItem => item.Rating)</div></p>
</td>
</tr>
<tr>
<td>
<h5>Feedback</h5>
</td>
<td>
<p><div align="left"> @Html.DisplayFor(modelItem => item.Feedback)</div></p>
</td>
</tr>
<tr><td colspan="2"><hr class="active" /></td></tr>
}
</table
因此,StudentWellnessReview和HAICUReviews Views顯示返回它們各自的查詢。但是我想要做的是在一個View上顯示這些查詢。你的幫助我將不勝感激。
在此先感謝
順便說一句,正確的方式來使用它是:@ { Html.RenderAction(「StudentWellnessReviews」,「評論」); }無需添加字控制器 –