我有一个问题,我一直在使用这个很好的其他人,我的课程如下
namespace WebApplication1.Models
{
public class Reviews
{
public int ReviewId { get; set; }
public DateTime ReviewDate { get; set; }
public string ReviewedBy { get; set; }
public string ShortDescription { get; set; }
public double Localknowledge { get; set; }
public double Processexpertise { get; set; }
public double Responsiveness { get; set; }
public double NegotiationSkills { get; set; }
}
}
我在我的代理类中使用它,如下所示:
public class Agents
{
public int AgentId { get; set; }
public int RatingsId { get; set; }
public string Name { get; set; }
public string About { get; set; }
public string Bookerish { get; set; }
public string Specialties { get; set; }
public int LicenseNo { get; set; }
public string image { get; set; }
public double LocalKnowledge { get; set; }
public double ProcessExpertise { get; set; }
public double Responsiveness { get; set; }
public double NegotiationSkills { get; set; }
public double RatingAverage { get; set; }
public List<Property> Properties { get; set; }
public List<PastSales> PastSales { get; set; }
public List<Reviews> Reviews { get; set; }
}
}
在我的索引文件中,我使用以下内容加载与其他视图相同的视图
<div class="l-divider l-divider--big"></div>
@Html.Partial("Reviews.cshtml", Model.Reviews)
In My Agent controller i have
_newAgent.PastSales = new List<PastSales> {
new PastSales { PastSalesId=1,address="3247 Greystone Dr • Jamul, CA 91935",image="/images/property/home5.jpg", Beds=7,Baths=4,SQFT="6,150" ,SoldDate= Convert.ToDateTime("12/09/2017"),Represented="Seller",Price=Convert.ToDecimal(900.0000m) },
new PastSales { PastSalesId=2,address="9951 Watergum Trl • Santee, CA 92071",image="/images/property/home4.jpg", Beds=6,Baths=5.5,SQFT="5,505" ,SoldDate= Convert.ToDateTime("21/7/2017"),Represented="Buyer",Price=Convert.ToDecimal(490.000m) },
new PastSales { PastSalesId=3,address="627 Hawthorne Ave • El Cajon, CA 92020", image="images/property/home12.jpg", Beds=6,Baths=5.5,SQFT="5,505" ,SoldDate= Convert.ToDateTime("11/09/2017"),Represented="Buyer",Price=Convert.ToDecimal(522.000m) },
new PastSales { PastSalesId=4,address="9565 Janfred Way • La Mesa, CA 91942", image="images/property/home6.jpg", Beds=6,Baths=5.5,SQFT="5,505" ,SoldDate= Convert.ToDateTime("11/09/2017"),Represented="Buyer",Price=Convert.ToDecimal(555.000m) },
new PastSales { PastSalesId=5,address="5160 Alzeda Dr • La Mesa, CA 91941", image="images/property/home7.jpg", Beds=6,Baths=5.5,SQFT="5,505" ,SoldDate= Convert.ToDateTime("11/09/2017"),Represented="Buyer",Price=Convert.ToDecimal(1.265) },
};
_newAgent.Reviews = new List<Reviews> { new Reviews { ReviewId=1, ReviewedBy="russroberts"} };
return View(_newAgent);
}
所以请有人告诉我为什么我会得到以下
InvalidOperationException:传递给的模型项 ViewDataDictionary的类型为'System.Int32',但是这个 ViewDataDictionary实例需要类型的模型项 'System.Collections.Generic.List`1 [WebApplication1.Models.Reviews]'。
我的观点如下所示
@model List<Reviews>
<h3>Ratings & Reviews</h3>
<div class="c-content__filter c-content__filter--reviews h-clearfix">
<div class="l-col l-col-4 l-col-xs-6">
<select class="l-form-control l-form-select l-form-elem-custom" id="reviewType_ReviewFilter">
<option>All reviews (16)</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="l-col l-col-4 l-col-xs-6">
<select class="l-form-control l-form-select l-form-elem-custom" id="reviewOrder_ReviewFilter">
<option>Newest first</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="l-col l-col-4 h-hide-on-mobile">
<button type="button" class="l-btn l-btn--action l-btn--blue">Write a Review</button>
</div>
</div>
@foreach (var item in Model)
{
<div class="c-content__reviews">
}