如何通过模型访问cshtml页面中的子列表

How to access the child lists in cshtml page through model

无法访问 cshtml 页面中的模型列表类型变量。 这是我的模特 Class

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>' does not contain a definition for 'plist' and no extension method 'plist' accepting a first argument of type 'IEnumerable<MBilling>' could be found (are you missing a using directive or an assembly reference?)

提前致谢。

问题:

您将模型作为 MBilling 类型的对象返回,但在视图中将其用作 IEnumerable<MBilling>

解决方案:

这里不需要IEnumerable<T>,因为它不可枚举。所以将其删除并执行以下操作:

@model Shop.Models.MBilling