我有一个名为_GetForfaitDashBoard.cshtml的局部视图 这是代码
@model WebAppComp.Areas.Admin.Models.StatsForfaitDashBoard
<table class ="table table-bordered">
<tr>
<th>Nombre total de Forfaits</th>
<th>Moyenne des forfaits par Agence</th>
<th>Forfait Ayant le prix le plus haut</th>
<th>Forfait Ayant le prix le plus bas</th>
<th>Le forfait le plus visité</th>
<th>Le forfait le mieux noté par les membres</th>
<th>le forfait ayant le plus de réservations</th>
<th>le forfait le plus récent</th>
</tr>
<tr>
<td>@Model.CountForfaits</td>
<td>@Model.AverageCountForfaitPerAgence</td>
<td>@Html.ActionLink("Ici", "GetById", "Agence", new { numSiretAgence = Model.IdHighestPriceForfait }, null)</td>
<td>@Html.ActionLink("Ici", "GetById", "Agence", new { numSiretAgence = Model.IdLowestPriceForfait }, null)</td>
<td>@Html.ActionLink("Ici", "GetById", "Agence", new { numSiretAgence = Model.IdMostVisitedForfait }, null)</td>
<td>@Html.ActionLink("Ici", "GetById", "Agence", new { numSiretAgence = Model.IdBestRatedForfait }, null)</td>
<td>@Html.ActionLink("Ici", "GetById", "Agence", new { numSiretAgence = Model.IdMostBookedForfait}, null)</td>
<td>@Html.ActionLink("Ici", "GetById", "Agence", new { numSiretAgence = Model.IdMostRecentForfait}, null)</td>
</tr>
</table>
这是我用统计数据表的表格。 我想要做的是将这些统计信息加载到基于表单的网页中,该表单将包含一个简单的下拉列表,用户可以选择他想要的统计信息类型。 以下是部分View Action的代码:
[HttpPost]
public PartialViewResult _GetForfaitDashBoard (TypeForfait typeForfait)
{
.....
}
现在我不知道怎么办才能把我所说的全部付诸行动。将一个表单放在基本视图中,发布到Partial View的操作将是一个好方法吗?或者是否有任何其他解决方案基于表单调用局部视图?谢谢
答案 0 :(得分:1)
由于您正在返回PartialView,我的建议是:
使用jQuery Change event从下拉列表中获取所选值并将其发布到服务器。
$("#yourdropdownid").change(function(e){}
然后发布您的数据(我的个人偏好是通过Ajax request,但您也可以使用Post function)到您的_GetForfaitDashBoard
操作,并在您的javascript中处理回复:
$("#yourdropdownid").change(function(e){
var selectedValue = this.val();
$.ajax({
url: $("#yourFormId").attr("action"),
type: "POST",
data: { typeForfait: selectedValue },
success: function(response){ $('#IdOfTheElementWhereYouWantToInsert').html(response) },
error: function(){ // handle your error }
});
}
success函数中的response
参数是partialView的渲染html。
假设您仅根据所选值设置统计类型,我建议您在操作中将参数类型从TypeForfait更改为string(或int)。
[HttpPost]
public PartialViewResult _GetForfaitDashBoard (string typeForfait)
{
}