简体   繁体   English

在ASP.NET MVC视图中的创建列表期间出错

[英]Getting error during create list in ASP.NET MVC View

I am trying to fetch the data from database using database first approach and want to display the data in a list.. I am trying the following code for this 我正在尝试使用数据库优先方法从数据库中获取数据,并希望在列表中显示数据。.我正在尝试以下代码

This is my Action method 这是我的动作方法

 public ActionResult transaction()
        {

            var result = from T in db.tbProcTransactions
                         select T.pServiceID;
            return View(result);
        }

and in my view I write this 我认为这是我写的

@model IEnumerable<LinQuery.Models.tbProcTransaction>

@{
    ViewBag.Title = "transaction";
}

<h2>transaction</h2>

@foreach (var serviceID in @Model.pServiceID)
{
    @serviceID;
}

But when I run this code I get this Error 但是当我运行这段代码时,我得到了这个错误

System.Collections.Generic.IEnumerable' does not contain a definition for 'pServiceID' and no extension method 'pServiceID' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?) System.Collections.Generic.IEnumerable'不包含'pServiceID'的定义,找不到扩展方法'pServiceID'接受类型为'System.Collections.Generic.IEnumerable'的第一个参数(是否缺少using指令或组装参考?)

I am unable to resolve this error Please resolve this error experts 我无法解决此错误,请解决此错误专家

Change your foreach statement to 将您的foreach语句更改为

@foreach (var serviceID in Model)
{
  @serviceID;
}

在“操作”中,选择T而不是T。pServiceID

Try this: 尝试这个:

@model IEnumerable<LinQuery.Models.tbProcTransaction>

@{
    ViewBag.Title = "transaction";
}

<h2>transaction</h2>

@foreach (var serviceID in Model)
{
    serviceID.pServiceID;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM