我实现了一个继承 TableServiceEntity 的类,它添加了一些名为 UserEntity 的属性。
在 View 中,我想做一个 foreach 循环来显示所有条目,如下所示:
@model MembershipUserCollection
如果我这样做
@foreach (UserEntity user in Model) {
<td>
@Html.DisplayFor(modelItem => user.ID_client)
</td>
<td>
@Html.DisplayFor(modelItem => user.Username)
</td>
....
....
}
VS2010 告诉我无法将对象类型从“System.Web.Security.MembershipUser”转换为“AzureTableStorage.UserEntity”。
如果我改变模型
@model UserEntity
这向我显示了另一个错误..
foreach 语句无法对“UserEntity”类型的变量进行操作,因为“UserEntity”不包含“GetEnumerator”的公共(public)定义
UserEntity 类具有这样声明的属性..
public class UserEntity : TableServiceEntity
{
public UserEntity(string partitionKey, string rowKey) : base(partitionKey, rowKey)
{
}
public UserEntity() : this(Guid.NewGuid().ToString(), String.Empty)
{
}
public int ID_client { get; set; }
public String Username { get; set; }
public String Password { get; set; }
public String Email { get; set; }
............ ………… ......
(其中用户名和其他一些属性与 MembershipUser 相同......但不是全部,我额外添加了 3 或 4 个)。
有人可以帮助我吗?
谢谢。
最佳答案
你所做的事情是行不通的。错误消息告诉您这一点。
这是所有该向导生成的代码的问题,在于您不了解它是如何工作的。因此,当出现问题时,您不知道如何修复它。我建议您了解为什么会出现错误。他们是有原因的。如果你了解了原因,解决方案就会更加明显。
关于asp.net - Foreach MVC3 成员(member)用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10384764/