ASP.NET Core 2 .1-如何在表中显示所有数据
我不知道如何将customerdata
放入客户名单
属性中。我已经在使用customerLists = customerdata;
,但是我有错误:
“客户名单”是一种类型,但像变量
一样使用
有人可以向我解释这一点吗?
这是我在index.cshtml.cs中的代码:
namespace WebApplication1.Pages
{
public class Pages : PageModel
{
public List<CustomerList> CustomerLists = new List<CustomerList>();
private readonly ApplicationDbContext _conn;
public Pages(ApplicationDbContext conn)
{
_conn = conn;
}
public int Message;
public void OnGet()
{
var CustomerData = _conn.table_customer.ToList();
//??
}
}
public class CustomerList
{
public string CustomerId;
public string Name;
public string Address;
public string MobileNo;
}
}
I don't know how to put CustomerData
into CustomerLists
property. I'm already using CustomerLists = CustomerData;
but I got error:
'CustomerLists' is a type but is used like a variable
Can anyone explain this to me?
This is my code in Index.cshtml.cs:
namespace WebApplication1.Pages
{
public class Pages : PageModel
{
public List<CustomerList> CustomerLists = new List<CustomerList>();
private readonly ApplicationDbContext _conn;
public Pages(ApplicationDbContext conn)
{
_conn = conn;
}
public int Message;
public void OnGet()
{
var CustomerData = _conn.table_customer.ToList();
//??
}
}
public class CustomerList
{
public string CustomerId;
public string Name;
public string Address;
public string MobileNo;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如前所述,您将
customerdata
分配给customerList
code> customerList
是一种类型。这是不正确的。您需要:
但是,仅当
customerdata
是list&lt; customerList&gt;
类型时。对于施法
customerdata
tolist&lt; customerList&gt;
键入类型,使用linq.select()
。或者,您可以直接分配
客户名单
值,而无需customerdata
变量。通过提供getter和设定器,将字段更改为属性。
As the error mentioned, you are assigning
CustomerData
toCustomerList
whichCustomerList
is a type. It's incorrect.You need:
But only when
CustomerData
is aList<CustomerList>
type.For casting
CustomerData
toList<CustomerList>
type, work with Linq.Select()
.Or you can straightway assign the
CustomerLists
value without the need forCustomerData
variable.Change the fields to properties by providing getter and setter.