所以我有一个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上显示这些查询。非常感谢您的帮助。
提前致谢
答案 0 :(得分:0)
以Kenneth的回应为基础:
您可以添加其他操作:
public ActionResult StudentWellnessReviewsAndHAICUReviews()
{
return View();
}
然后在StudentWellnessReviewsAndHAICUReviews.cshtml:
@Html.Action("ReviewsController", "StudentWellnessReviews")
@Html.Action("ReviewsController", "HAICUReviews")