我在尝试使用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 模型上。非常感谢您对如何帮助我理解此错误的任何想法。
编辑:
最佳答案
显然,如果您已经声明了某些内容,则无法使用“模型”进行声明?
好吧,为了更好地解释它,这就是对我有所帮助的原因。
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/