c# - 错误CS0135 : 'Model' conflicts with the declaration 'System.Web.Mvc.ViewPage<TModel>.Model'

标签 c# asp.net-mvc model-view-controller mvvm telerik

我在尝试使用ViewModel在 View 中实现forloop时遇到问题。

我有这个ViewModel

public class EventDashboard
{
    public int Id {get;set;}

    public string Name {get;set;}
    public string Email {get;set;}
    public string Phone {get;set;}

    public ICollection<FighterDetails> FightersFees{ get; set; }

    public void LoadFighterDetails(int eventId, int fighterId, aContext ac, bContext bc){

        Fighters fighter = ac
            .Fighters
            .Include(npo => npo.FighterAddress)
            .FirstOrDefault(npo => npo.FighterId== fighterId);

        this.Name = fighter.Name;
                    this.Email = fighter.Email;
                    this.Phone = fighter.Phone;

        LoadFees(bc, fighterId);
    }

    public void LoadFees(bContext bc, int fighterId)
    {
                 var fees = bc.Fees.Where(f => f.fighterId == fighterId);
                 FightersFees = new List<FighterDetails>();

                 foreach(var f in fees){
                    this.FightersFees.Add(new FighterDetails{
                             //fill the properties
                       });
                 }
            }
    }

public class FighterDetails
{
    public string FighterName { get; set; }
    public int fighterId { get; set; }
    public decimal FighterFee { get; set; }
}

在我看来:
        <% foreach( var d in Model.Fighters){ %>
        <%} %>

但它会不断排除该错误(关于主题)。想知道为什么它发生在 View 模型上。非常感谢您对如何帮助我理解此错误的任何想法。

编辑:
  • 添加了其余代码
  • ,该项目当前正在使用ef 4.0。不知道这是否有意义。
  • 最佳答案

    显然,如果您已经声明了某些内容,则无法使用“模型”进行声明?

    好吧,为了更好地解释它,这就是对我有所帮助的原因。
    Model conflicts with declaration

    我实际上是在前几个编辑框中声明了Model。
    例如。 <%: Html.DisplayFor(Model => Model.FighterName)%>
    然后在foreach上再次调用它。首次声明它会导致该错误。

    关于c# - 错误CS0135 : 'Model' conflicts with the declaration 'System.Web.Mvc.ViewPage<TModel>.Model' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8095309/

    相关文章:

    C# - 是否可以隐藏公开继承的方法(例如,对派生类私有(private))

    c# - 使用 LINQ ForEach 循环的替代方法是什么?

    asp.net-mvc - 如何让 T4MVC 使用像 "{controller}/{action}/{id}"这样的路由?

    c# - C#-如何按顺时针顺序(tl,tr,br,bl)对4点列表进行排序,以用于opencv getPerspective?

    ASP.NET MVC 和 httpRuntime 执行超时

    c# - 如何将 Newton.Json 反序列化通用对象转换为自定义对象?

    PHP MVC : Registry class

    c# - 在 MVC 中使用 HTML 按钮

    objective-c - Xcode 4.2 & Storyboard,如何访问另一个类的数据?

    c# - 如何更新链接到 List<string> 的数组