C# 错误CS0135:&x27;型号';与声明冲突';System.Web.Mvc.ViewPage<;TModel>;。型号';
我在尝试使用ViewModel在视图中实现forloop时遇到问题 我有这个模型C# 错误CS0135:&x27;型号';与声明冲突';System.Web.Mvc.ViewPage<;TModel>;。型号';,c#,asp.net-mvc,model-view-controller,mvvm,telerik,C#,Asp.net Mvc,Model View Controller,Mvvm,Telerik,我在尝试使用ViewModel在视图中实现forloop时遇到问题 我有这个模型 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>
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; }
}
公共类事件仪表板
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串电子邮件{get;set;}
公用字符串电话{get;set;}
公共ICollection FightersFees{get;set;}
public void LoadFighterDetails(int-eventId、int-fighterId、aContext-ac、bContext-bc){
战斗机=ac
.战斗机
.包括(npo=>npo.FighterAddress)
.FirstOrDefault(npo=>npo.FighterId==FighterId);
this.Name=fighter.Name;
this.Email=fighter.Email;
this.Phone=fighter.Phone;
装载费(不列颠哥伦比亚省,fighterId);
}
公共无效装载费(bContext bc,int fighterId)
{
var费用=bc费用,其中(f=>f.fighterId==fighterId);
FightersFees=新列表();
foreach(费用中的var f){
此.FightersFees.Add(新FighterDetails){
//填充属性
});
}
}
}
公开课详细信息
{
公共字符串FighterName{get;set;}
公共int fighterId{get;set;}
公共十进制FighterFee{get;set;}
}
我认为:
<% foreach( var d in Model.Fighters){ %>
<%} %>
但它(在这个问题上)不断地推出这个错误。想知道为什么它会发生在viewmodels上。任何关于如何帮助我理解这个错误的想法都是非常感谢的
编辑:
- 添加了代码的其余部分
- 该项目目前正在使用EF4.0。不确定这是否相关
例如,
Model.FighterName)%>
然后在foreach上再次调用它。您第一次声明它时会导致错误。您确定这是错误发生的那一行吗?似乎您在视图中的某个位置声明了另一个名为
Model
的变量。是的,是同一行。即使我试着把它放在telerik网格上,它也会给我这个错误。你能从你的观点中包含更多的代码吗?老板,得到答案了。谢谢你的回复。(包括在帖子中)太棒了——谢谢!我也有同样的问题。似乎VisualStudio应该标记问题,而不是副作用。(我明白在这种情况下,我就是问题所在——但我喜欢VS来拯救我自己。)