渲染ChildAction时遇到问题:
[ChildActionOnly]
public ActionResult ListAll()
{
var user_id = (int)Membership.GetUser().ProviderUserKey;
var client_id = from d in db.Connexions
where d.userId == user_id && d.Action == "Creation"
select d.ClientID;
//var cust_id = (int)client_id;
var lastClient = from d in db.Clients
where d.ClientID == client_id.Max()
select d;
return View(lastClient);
}
我在创建页面中将其呈现在这里:
<div class="editor-label">
@Html.LabelFor(model => model.dateOut)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.dateOut)
@Html.ValidationMessageFor(model => model.dateOut)
</div>
<p> @{Html.RenderAction("ListAll");} </p> //---- Here
我不知道为什么HttpException会出现详细错误:执行处理程序的子请求时出错&#39; System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper&#39;。
这是我的ListAll局部视图,并使用客户端模型进行强类型化:
@model Gestion_restrictions.Models.Client
<th>
@Html.DisplayNameFor(model => model.portfolio)
</th>
<th>
@Html.DisplayNameFor(model => model.dateIn)
</th>
<td>
@Html.DisplayFor(modelItem => item.portfolio)
</td>
等...
有人能帮助我吗?
谢谢
答案 0 :(得分:0)
视图的模型定义为Client
,但您传递的是IEnumerable<Client>
。更改以下
var lastClient = from d in db.Clients
where d.ClientID == client_id.Max()
select d;
到
var lastClient = (from d in db.Clients
where d.ClientID == client_id.Max()
select d).FirstOrDefault(); // or .SingleOrDefault()
return View(lastClient);