我正在从Web api接收数据,但不知道如何将Icollection的内容获取到我的Model对象中
Api控制器
公共IHttpActionResult Campaigndetails(int id) {
$(document).ready(function () {
$('tr').click(function () {
if(this.style.background == "" || this.style.background =="white") {
$(this).css('white-space', 'normal');
}
else {
$(this).css('white-space', 'nowrap');
}
});
});
广告系列控制器:
公共ActionResult详细信息(整数id) {
IList<CampaignViewModel> list = null;
using (IdonateEntities2 entities = new IdonateEntities2())
{
list = entities.Campaigns.Include(x => x.Donors).Select(x =>
new CampaignViewModel()
{
campaign_id = x.campaign_id,
title = x.title,
description = x.description,
amount = x.amount,
image = x.image,
raised_amount = x.raised_amount,
category_id = x.category_id,
user_id = x.user_id,
Donor = x.Donors.Select(d=> new DonorViewModel()
{
donor_id = d.donor_id,
donor_name = d.donor_name,
donated_amount = d.donated_amount,
campaign_id = d.campaign_id,
payment_id = d.payment_id
}).ToList()
}).ToList().Where(x => x.campaign_id == id).ToList();
return Ok(list);
}
我的模型班:
公共类类别 {
List<Category> category = new List<Category>();
string text = string.Empty;
var request = WebRequest.Create("http://localhost:49210/api/campaign/campaigndetails/"+ id);
var response = (HttpWebResponse)request.GetResponse();
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
category = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<List<Category>>(text);
}
return View(category);
}
文本显示了Web API接收到的所有数据,但category对象在Donor中未显示任何数据,我想接收它并传递给我的视图以显示