HTML.Action引发异常:System.Web.dll中发生了类型为'System.Web.HttpException'的异常 [英] Html.Action throwing exception: An exception of type 'System.Web.HttpException' occurred in System.Web.dll
问题描述
我从博客主布局中的 @ Html.Action("getCategory","Blogs")
中收到此错误.
I'm getting this error from @Html.Action("getCategory", "Blogs")
in the master layout for my blog.
错误是:
System.Web.dll中发生类型'System.Web.HttpException'的异常,但未在用户代码中处理附加信息:执行处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'的子请求时出错.
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code Additional information: Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
这是我的控制人:
public ActionResult getCategory()
{
var categories = _repo.getBlogs().Select(c => new
{
c.Category
}).ToList();
return PartialView("_category", categories);
}
这是我的部分观点:
@model IEnumerable<MainSite.Data.Blog>
<div class="sw_categories">
<div class="sw_title">
<h4>Categories</h4>
</div>
<ul class="arrows_list">
@foreach (var c in Model)
{
<li><a href="#">@c</a></li>
}
</ul>
</div>
我对ASP.NET MVC还是很陌生,所以任何人都可以向我解释该错误以及如何解决此问题吗?
I'm pretty new to ASP.NET MVC, so could anyone please explain the error to me and how I could fix this?
推荐答案
您要么想要..
-
从
getCategory()
返回博客的集合,因为这是您的部分期望值:
return a collection of Blogs from
getCategory()
, since that is what your partial is expecting:
IEnumerable<MainSite.Data.Blog>
或更改局部模型的类型以与您从 getCategory()
返回的内容相对应.示例:
or change the model type in the partial to correspond with what you're returning from getCategory()
. Example:
IEnumerable<MainSite.Data.Blog.Category>
这篇关于HTML.Action引发异常:System.Web.dll中发生了类型为'System.Web.HttpException'的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!