Asp.Net MVC2 Error in view

谁说胖子不能爱 提交于 2019-12-24 21:48:37

问题


I am new to MVC and I have been following Steven Andersons Pro ASP.Net Mvc 2 framework book but have encountered the following issue.

The following line of code that sits in my site.Master file throws the following error:

<% Html.RenderAction("Menu", "Nav"); %>

{"Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'."}

The problem seems to be within my Partial View that is trying to render the result of the above code.

The actual error that is out put in the browser is as follows:

Could not load type System.Web.Mvc.ViewUserControl<IEnumerable<WebUI.Models.NavLink>>.

my partial view consists of the following:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<WebUI.Models.NavLink>>" %>
<%foreach (var link in Model) { %>
<%: Html.RouteLink(link.Text, link.RouteValues }%>

There also seems to be no IntelliSense available for for the Model.

I know it has something to do with the Inheritance but I have checked the namespace and this appears to be correct.

Any help on this would be much appreciated.

Thanks in advance


回答1:


I'm working through Sanderson's book and had the same problem. The solution is that the file is named NavLink.cs while the menu inherits from NavLinks. Correct the link or rename the file and everything works.

Interesting problem that begs one question: How did you determine from the error message that this was a namespace issue? Earl B.




回答2:


I've gotten Anderson's examples working from the first edition of that book. One thing I noticed is that my NavLink is defined in Controllers/NavController.cs and has a namespace of WebUI.Controllers as opposed to WebUI.Models (thus the type is IEnumerable<WebUI.Controllers.NavLink>. The error you are reporting certainly sounds like a namespace issue...

EDIT: One thing I found that helped me troubleshoot those examples was to download his source code and use a file comparison tool to compare his version to mine when I ran into a problem that I just couldn't figure out.




回答3:


I have also found the the original idea of putting the classes into one file NavController.cs also creates this error.

Separate the classes into 3 files NavController.cs NavLink.cs CategoryLink.cs

All with the same Namespace namespace WebUI.Controllers

and it should solve the issue



来源:https://stackoverflow.com/questions/3737556/asp-net-mvc2-error-in-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!