简体   繁体   中英

Asp.Net MVC2 Error in view

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

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM