Asp.Net MVC2 Error in view - c#

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'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.

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 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

Related

C# MVC5 View not recognizing namespace

I have recently run on this problem. I have tried to add namespace to Views/web.config or on top of the view, but still occur on the problem, where View can't find the contents of namespace.
Problem
Ofcorse it is not a big problem, but it is annoying to always write the full namespace.
Maybe you should try write another using that contains your Resources path?

Parser Error Could not load type 'testconnect.index'

I have encountered an error that prevents me from uploading the webpage to the server. I managed to let it work without any errors when I am running visual studio.
Here's the error
However, when I removed Inherits="testconnect.index" , it can work but it cannot connect index.aspx.cs to index.aspx.
Like for example:
With lbl_test.Text inside the index.aspx
Does anyone knows how to fix the error?
You're trying to inherit from testconnect.index, but your class is named index1. Can you change the class name to index? Or, conversely, set the Inherits directive to inherit from testconnect.index1?
You have to specify the exact name of the class in order to reference it. "Close enough" isn't close enough.
(Note also that Visual Studio is trying to tell you in your index1 class that lbl_test doesn't exist. Supposedly perhaps the designer partial class is index? If that's the case, you'll probably want to just rename this partial class to index as well.)
Okay I have got it working by changing CodeBehind="index.master.cs" to CodeFile="index.master.cs". I learned that you will have to compile the file first if you want to use CodeBehind. Other than that, it is recommended not to name the aspx page exactly similar to masterpage.

Values cannot be returned until Resolution is frozen (Upgrade Umbraco version 4.9.1 to 4.11.1)

When I upgraded umbraco V4.9.1 to V4.11.1, in last step I have encountered a problem.
I just overwrite the /bin, /install, /umbraco and /umbraco_client folder and run it.
Problem was "Values cannot be returned until Resolution is frozen".
PLEASE HELP ME.
As #Dave linked, the actual root of the issue comes from Global.asax.cs not inheriting from the Umbraco.Web.UmbracoApplication class.
I know this is an old post, but it is unanswered and the resolution at this point (a comment) does not solve the issue for everybody as it is not even an option for many upgrading users as the route mentioned will overwrite ones global.asax . -Just want to give quick mark for posterity so this question is answered with a universal resolution.
Try out the following Steps.,
delete global.asax from server
refresh site
copy again global.asax on server
enter code hereif You have Global.asax file like following
<%# Application Codebehind="Global.asax.cs" Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %>
delete your Global.asax and add global application class
then in your code behind, change System.Web.HttpApplication to UmbracoApplication
public partial class Global : UmbracoApplication
{
}

Make sure that the class defined in this code file matches the 'inherits' attribute,

Sometimes in my web applications I used to get this sort of error, I have no clue why is it coming however if I refresh the page few times the page is loading normally.
I am using .net framework 2.0 and visual web developer 2005.
I have only ever seen this error message when the class that is contained in your file is diffrent from the class being called in the HTML page
For example at the top of your html page there will be a line of code that goes something like this:<%# Page Language="C#" AutoEventWireup="true" CodeFile="#whereyourcodeis.aspx.cs" Inherits="#ClassName" Title="whatever" %>
and in your whereyourcodeis.aspx.cs file there should be a constructor method that has the same name as the inherits line in your html. ie Class ClassName{ rest of your code}
If for some reason these two names do not match you get the error you have, hope this can shine some light on where your code is going wrong
It happened to me when by accident I changed the codefile of another aspx file to point to the same code file as the current page file.
Make sure each aspx file point to the correct code file. Visual studio doesn't point you to the right file.
You can try and search the name of the file that causes the error to find the other page pointing to it.

Validation of ViewState MAC Failed

Sorry if this is duplicate but I've been going crazy for the past two hours over this.
After changing the Master Page in ASP.NET MVC 1.0 application, I keep getting this familiar error when I try a postback without filling in the mandatory form elements which are validated by the server:
"Validation of viewstate MAC failed.
If this application is hosted by a Web
Farm or cluster, ensure that
configuration specifies
the same validationKey and validation
algorithm. AutoGenerate cannot be used
in a cluster."
The new page refers to a lot of jQuery code with lightboxes, superfish etc. Could that be a problem while doing a postback?
If I revert back to the original master, the error disappears and I'm able to validate form fields. Both masters are located in the same path.
I know a lot of other guys have faced this issue but I was unable to find anything which could help me.
Thanks.
Edited and added
After a little debugging, I've realized that a directive in the master page:
<% Html.RenderAction("menu", "nav"); %>
is creating the problem. The directive asks the "menu" action of the controller "nav" to inject a partial view Menu.ascx. If I delete this line from the new master page, everything works OK. My app's left bar navigation relies on this directive to work properly. Is there any way I can get around this? Very mysterious.
Are you using Html.AntiForgeryToken() anywhere on this page? Sometimes when I am testing locally with multiple different sites and / or port changes this will happen to me. If it does I clear my browser cache and it works just fine.
I did experienced the same problem two days ago. :)
A simple restart of the box has worked in my case so I did'nt investigate further.

Categories