asp.net - Foreach MVC3 成员(member)用户

标签 asp.net c asp.net-mvc-3 foreach

我实现了一个继承 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/

相关文章:

.net - 如何让 Elmah 使用 ASP.NET 和 IIS 5.1 URL 路由

c# - 突出显示 Asp.net 图表控件系列中的一列

c - C语言判断进程是否空闲

c# - MVC3 : Overriding the Model values in HTTPPost action method

asp.net - 自定义Web字体在IE9中不起作用

asp.net - 使用 Coldfusion 7 中的 WCF 服务

ASP.NET Web.Api 插件架构

c - GTK Linux C 通过按钮小部件从输入框获取输入

c - 错误:“User,User.szMake”之前的预期表达式

asp.net-mvc-3 - Razor 局部 View 未呈现