使用IEnumerable以列表格式获取数据,如何从控制器返回查看页面。
model.Name = UserPermissions.Name;这是正确的格式吗?
包含每个计划的名称,ID,金额,货币的列表。
model.Name = UserPermissions.Name;在这里得到错误。从列表传递所有数据以在DIV中动态查看。如何传递数据并在视图中显示。帮助我们
public ActionResult Plans(Plan model)
{
var planServicenew = new StripePlanService(apiKey);
IEnumerable<StripePlan> responsenew = planServicenew.List();
foreach (var UserPermissions in responsenew)
{
model.Name = UserPermissions.Name;
}
return View(model);
}
@model IEnumerable<ABACUS.Models.Plan>
@foreach (var item in Model)
{
<div class="plan">
<h3 class="plan-title">@Html.DisplayFor(modelItem => item.Name)</h3>
<p class="plan-price">@Html.DisplayFor(modelItem => item.Currency)@Html.DisplayFor(modelItem => item.Amount) <span class="plan-unit">per month</span></p>
<ul class="plan-features">
<li class="plan-feature">@Html.DisplayFor(modelItem => item.Trial)-days <span class="plan-feature-name">Trial</span></li>
</ul>
<a href="#" class="plan-button">Choose Plan</a>
</div>
}
答案 0 :(得分:2)
考虑到您有“计划”模式,并且您希望将计划列表传递给您的视图,
尝试以下方式解决您的问题 -
var planServicenew = new StripePlanService(apiKey);
IEnumerable<StripePlan> responsenew = planServicenew.List();
var plans = (from r in responsenew
select new Plan
{
Name = r.Name,
Currency = r.Currency,
Amount = r.Amount,
Trial = r.Trial
}).ToList() as List<Plan>;
return View(plans);