【发布时间】:2019-01-15 14:58:15
【问题描述】:
无法访问 cshtml 页面中的模型列表类型变量。 这是我的模型类
public class MBilling
{
public List<string> plist { get; set; }
public List<decimal> qlist { get; set; }
public List<decimal> splist { get; set; }
}
控制器
public ActionResult Billing()
{
if (Session["UserId"] != null)
{
MBilling binddata = BillingService.getBindData();
return View(binddata);
}
else
{
return this.RedirectToAction("Index", "Login");
}
}
这里是cshtml部分
@model IEnumerable<Shop.Models.MBilling>
@{
ViewBag.Title = "Billing";
}
<input style="border:none" list="browsers" name="browser">
<datalist id="browsers">
///Unable to ACCESS Model.plist
@foreach (var item in Model.plist)
{
}
</datalist>
我能够从服务文件中获取具有所需数据的模型对象,但在 cshtml 页面中显示错误
CS1061:“
IEnumerable<MBilling>”不包含“plist”的定义,并且找不到接受“IEnumerable<MBilling>”类型的第一个参数的扩展方法“plist”(您是否缺少 using 指令或程序集参考?)
提前致谢。
【问题讨论】:
-
你的 rmodel 是一个 IEnumerable,所以你需要一个索引。
Model[i].plist或许?
标签: c# asp.net asp.net-mvc asp.net-mvc-4