Html.RenderAction error - asp.net-mvc

I have a ASP.NET MVC 1 application and using Visual Web Developer Express. I can not get the Html.RenderAction("Controller","Action") to work on my MasterPage. (Site.Master) in the Shared folder.
VWD says "Html" is not recognized here.
I took to the following steps to implement the Html.RenderAction("Controller","Action") method.
Downloaded Micrsoft.Web.Mvc.dll
Updated the web.config with a reference to Micrsoft.Web.Mvc.dll '
I added a reference to Micrsoft.Web.Mvc.dll in my project manually.
I'm following the book: Pro ASP.NET MVC Framework by Steven Sanderson and downloaded the sample file where he covers this topic (Ch 4 - 6) and his sample file is giving me the same error?
Please help!
Thanks!
Quinntyne

Sample code would help.
A few things:
Html.RenderAction() is not available in MVC 1, it was added in MVC 2. That's probably not the cause of your error message though.
When you say that you "added a reference in your web.config,", make sure you added the namespaces to the namespaces section:
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
Adding that last one will probably address the issue.

Related

HTTP Error 404.0 - Not Found on action in controller. MVC [duplicate]

I have a project that requires my URLs have dots in the path. For example I may have a URL such as www.example.com/people/michael.phelps
URLs with the dot generate a 404. My routing is fine. If I pass in michaelphelps, without the dot, then everything works. If I add the dot I get a 404 error. The sample site is running on Windows 7 with IIS8 Express. URLScan is not running.
I tried adding the following to my web.config:
<security>
<requestFiltering allowDoubleEscaping="true"/>
</security>
Unfortunately that didn't make a difference. I just receive a 404.0 Not Found error.
This is a MVC4 project but I don't think that's relevant. My routing works fine and the parameters I expect are there, until they include a dot.
What do I need to configure so I can have dots in my URL?
I got this working by editing my site's HTTP handlers. For my needs this works well and resolves my issue.
I simply added a new HTTP handler that looks for specific path criteria. If the request matches it is correctly sent to .NET for processing. I'm much happier with this solution that the URLRewrite hack or enabling RAMMFAR.
For example to have .NET process the URL www.example.com/people/michael.phelps add the following line to your site's web.config within the system.webServer / handlers element:
<add name="ApiURIs-ISAPI-Integrated-4.0"
path="/people/*"
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
Edit
There are other posts suggesting that the solution to this issue is RAMMFAR or RunAllManagedModulesForAllRequests. Enabling this option will enable all managed modules for all requests. That means static files such as images, PDFs and everything else will be processed by .NET when they don't need to be. This options is best left off unless you have a specific case for it.
After some poking around I found that relaxedUrlToFileSystemMapping did not work at all for me, what worked in my case was setting RAMMFAR to true, the same is valid for (.net 4.0 + mvc3) and (.net 4.5 + mvc4).
<system.webserver>
<modules runAllManagedModulesForAllRequests="true">
Be aware when setting RAMMFAR true Hanselman post about RAMMFAR and performance
I believe you have to set the property relaxedUrlToFileSystemMapping in your web.config. Haack wrote an article about this a little while ago (and there are some other SO posts asking the same types of question)
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true" />
Edit
From the comments below, later versions of .NET / IIS may require this to be in the system.WebServer element.
<system.webServer>
<httpRuntime relaxedUrlToFileSystemMapping="true" />
I got stuck on this issue for a long time following all the different remedies without avail.
I noticed that when adding a forward slash [/] to the end of the URL containing the dots [.], it did not throw a 404 error and it actually worked.
I finally solved the issue using a URL rewriter like IIS URL Rewrite to watch for a particular pattern and append the training slash.
My URL looks like this: /Contact/~firstname.lastname so my pattern is simply: /Contact/~(.*[^/])$
I got this idea from Scott Forsyth, see link below:
http://weblogs.asp.net/owscott/handing-mvc-paths-with-dots-in-the-path
Just add this section to Web.config, and all requests to the route/{*pathInfo} will be handled by the specified handler, even when there are dots in pathInfo. (taken from ServiceStack MVC Host Web.config example and this answer https://stackoverflow.com/a/12151501/801189)
This should work for both IIS 6 & 7. You could assign specific handlers to different paths after the 'route' by modifying path="*" in 'add' elements
<location path="route">
<system.web>
<httpHandlers>
<add path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="ApiURIs-ISAPI-Integrated-4.0" path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</location>
MVC 5.0 Workaround.
Many of the suggested answers doesn't seem to work in MVC 5.0.
As the 404 dot problem in the last section can be solved by closing that section with a trailing slash, here's the little trick I use, clean and simple.
While keeping a convenient placeholder in your view:
#Html.ActionLink("Change your Town", "Manage", "GeoData", new { id = User.Identity.Name }, null)
add a little jquery/javascript to get the job done:
<script>
$('a:contains("Change your Town")').on("click", function (event) {
event.preventDefault();
window.location.href = '#Url.Action("Manage", "GeoData", new { id = User.Identity.Name })' + "/";
});</script>
please note the trailing slash, that is responsible for changing
http://localhost:51003/GeoData/Manage/user#foo.com
into
http://localhost:51003/GeoData/Manage/user#foo.com/
Super easy answer for those that only have this on one webpage. Edit your actionlink and a + "/" on the end of it.
#Html.ActionLink("Edit", "Edit", new { id = item.name + "/" }) |
Depending on how important it is for you to keep your URI without querystrings, you can also just pass the value with dots as part of the querystring, not the URI.
E.g. www.example.com/people?name=michael.phelps will work, without having to change any settings or anything.
You lose the elegance of having a clean URI, but this solution does not require changing or adding any settings or handlers.
You might want to think about using dashes instead of periods.
In Pro ASP MVC 3 Framework they suggest this about making friendly URLs:
Avoid symbols, codes, and character sequences. If you want a word
separator, use a dash (/my-great-article). Underscores are unfriendly,
and URL-encoded spaces are bizarre (/my+great+article) or disgusting
(/my%20great%20article).
It also mentions that URLs should be be easy to read and change for humans. Maybe a reason to think about using a dash instead of a dot also comes from the same book:
Don't use file name extensions for HTML pages (.aspx or .mvc), but do use them for specialized file types (.jpg, .pdf, .zip, etc). Web browsers don't care about file name extensions if you set the MIME type appropriately, but humans still expect PDF files to end with .pdf
So while a period is still readable to humans (though less readable than dashes, IMO), it might still be a bit confusing/misleading depending on what comes after the period. What if someone has a last name of zip? Then the URL will be /John.zip instead of /John-zip, something that can be misleading even to the developer that wrote the application.
Would it be possible to change your URL structure?
For what I was working on I tried a route for
url: "Download/{fileName}"
but it failed with anything that had a . in it.
I switched the route to
routes.MapRoute(
name: "Download",
url: "{fileName}/Download",
defaults: new { controller = "Home", action = "Download", }
);
Now I can put in localhost:xxxxx/File1.doc/Download and it works fine.
My helpers in the view also picked up on it
#Html.ActionLink("click here", "Download", new { fileName = "File1.doc"})
that makes a link to the localhost:xxxxx/File1.doc/Download format as well.
Maybe you could put an unneeded word like "/view" or action on the end of your route so your property can end with a trailing / something like /mike.smith/view
As solution could be also considering encoding to a format which doesn't contain symbol., as base64.
In js should be added
btoa(parameter);
In controller
byte[] bytes = Convert.FromBase64String(parameter);
string parameter= Encoding.UTF8.GetString(bytes);
It's as simple as changing path="." to path="". Just remove the dot in the path for ExensionlessUrlHandler-Integrated-4.0 in web.config.
Here's a nice article https://weblog.west-wind.com/posts/2015/Nov/13/Serving-URLs-with-File-Extensions-in-an-ASPNET-MVC-Application
Tried all the solutions above but none of them worked for me. What did work was I uninstalling .NET versions > 4.5, including all its multilingual versions; Eventually I added newer (English only) versions piece by piece. Right now versions installed on my system is this:
2.0
3.0
3.5 4
4.5
4.5.1
4.5.2
4.6
4.6.1
And its still working at this point. I'm afraid to install 4.6.2 because it might mess everything up.
So I could only speculate that either 4.6.2 or all those non-English versions were messing up my configuration.
I was able to solve my particular version of this problem (had to make /customer.html route to /customer, trailing slashes not allowed) using the solution at https://stackoverflow.com/a/13082446/1454265, and substituting path="*.html".
Add URL Rewrite rule to Web.config archive. You need to have the URL Rewrite module already installed in IIS. Use the following rewrite rule as inspiration for your own.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Add trailing slash for some URLs" stopProcessing="true">
<match url="^(.*(\.).+[^\/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Also, (related) check the order of your handler mappings. We had a .ashx with a .svc (e.g. /foo.asmx/bar.svc/path) in the path after it. The .svc mapping was first so 404 for the .svc path which matched before the .asmx.
Havn't thought too much but maybe url encodeing the path would take care of this.
This is the best solution I have found for the error 404 on IIS 7.5 and .NET Framework 4.5 environment, and without using: runAllManagedModulesForAllRequests="true".
I followed this thread: https://forums.asp.net/t/2070064.aspx?Web+API+2+URL+routing+404+error+on+IIS+7+5+IIS+Express+works+fine and I have modified my web.config accordingly, and now the MVC web app works well on IIS 7.5 and .NET Framework 4.5 environment.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
[RoutePrefix("File")]
[Route("{action=index}")]
public class FileController : Controller
{
// GET: File
public ActionResult Index()
{
return View();
}
[AllowAnonymous]
[Route("Image/{extension?}/{filename}")]
public ActionResult Image(string extension, string filename)
{
var dir = Server.MapPath("/app_data/images");
var path = Path.Combine(dir, filename+"."+ (extension!=null? extension:"jpg"));
// var extension = filename.Substring(0,filename.LastIndexOf("."));
return base.File(path, "image/jpeg");
}
}
}

MVC ASPX To Razor - Register webcontrol

I converted my MVC 3 project from to aspx to razor, having a problem with this line:
ASPX:
<%# Register TagPrefix="cc1" Namespace="WebControlCaptcha" Assembly="WebControlCaptcha" %>
Razor:
#{
Register TagPrefix="cc1" Namespace="WebControlCaptcha" Assembly="WebControlCaptcha";
}
Here is the error:
Compiler Error Message: CS1002: ; expected
Thanks in advance.
You can put, in the web.config inside Views folder, the following key:
<configuration>
<system.web>
<pages>
<controls>
<add assembly="WebControlCaptcha" namespace="WebControlCaptcha" tagPrefix="cc1" />
</controls>
</pages>
</system.web>
</configuration>
In my case, the application pool was set to use integrated pipeline mode with .NET Framework 2.0. The CAPTCHA image would not generate. I changed the application pool to use "Classic" while leaving the .NET Framework option the same and this fixed the image generation issue.

MVC 4 #Scripts "does not exist"

I have just created an ASP.NET MVC 4 project and used Visual Studio 2012 RC to create a Controller and Razor Views for Index and Create Actions.
When I came to run the application, and browsed to the Create view, the following error was shown:
Compiler Error Message: CS0103: The name 'Scripts' does not exist in
the current context
The problem is the following code which was added automatically to the bottom of the View:
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
Why does Scripts not exist?
I looked at the base Web Page class in Assembly System.Web.Mvc.dll, v4.0.0.0
I can see the following helper properties available:
Ajax
Html
Url
But nothing named Scripts.
Any ideas?
EDIT:
My Web.config file looks like this (untouched from the one that Visual Studio created):
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
EDIT #2:
People are blogging about using the #Scripts helper:
SCOTT HANSELMAN Blog
Codebetter.com
Yet having just installed Visual Studio 2012 RC onto a fresh Windows 8 install I am still unable to use #Scripts even though Visual Studio adds it to the generated View!
Solutions are presented below.
I am not sure how to close this, because in the end an update seemed to resolve the issue. I double checked I had performed a clean install, using a new project. But the same failing project I had made works fine now after various updates and no manual obvious intervention. Thanks for all of the thoughts but there was definitely an issue at the time ;)
The key here is to add
<add namespace="System.Web.Optimization" />
to BOTH web.config files. My scenario was that I had System.Web.Optimization reference in both project and the main/root web.config but #Scripts still didn't work properly. You need to add the namespace reference to the Views web.config file to make it work.
UPDATE:
Since the release of MVC 4 System.Web.Optimization is now obsolete. If you're starting with a blank solution you will need to install the following nuget package:
Install-Package Microsoft.AspNet.Web.Optimization
You will still need to reference System.Web.Optimization in your web.config files. For more information see this topic:
How to add reference to System.Web.Optimization for MVC-3-converted-to-4 app
As many pointed out, restart of VS could be required after the above steps to make this work.
#Styles and #Scripts are 2 new helpers provided by System.Web.Optimization library. As the name suggests, they bundle and minify CSS and JavaScript files or resources respectively.
Try including the namespace System.Web.Optimization either by #using directive or through web.config
http://ofps.oreilly.com/titles/9781449320317/ch_ClientOptimization.html#BundlingAndMinification
UPDATE
Microsoft has moved the bundling/minification to a separate package called Microsoft.AspNet.Web.Optimization. You can download the assembly from nuget.
This post will be useful to you.
There was one small step missing from the above, which I found on another post. After adding
<add namespace="System.Web.Optimization" />
to your ~/Views/web.config namespaces, close and re-open Visual Studio. This is what I had to do to get this working.
I am using areas, and have just come up against this issue, I just copied the namespaces from the root web.config to the areas web. config and it now works!!
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
I had the same problem and I used WinMerge to help me track this down. But as I researched it more, I found that Rick has the perfect blog post for it.
Summary:
Add <add namespace="System.Web.Optimization"/> to both web.config files
Run Install-Package -IncludePrerelease Microsoft.AspNet.Web.Optimization
Update Bundling code
Update Layout file
The last step is to update 10 other libraries. I didn't and it worked fine. So looks like you can procrastinate this one (unless I already updated 1 or more of them). :)
I had the same issue:
The System.Web.Optimization version I was using was outdated for MVC4 RC.
I updated my packages using the package manager in VS 2010.
In this MSDN blog, Mr. Andy talks about how to update your MVC 4 Beta project to MVC 4 RC. Updating my packages got the Scripts (particularly the web optimization one) to resolve for me:
To install the latest System.Web.Optimization package, use Package Manager Console (Tools -> Library Package Manager -> Package Manager Console) and run the below command:
Install-Package -IncludePrerelease Microsoft.AspNet.Web.Optimization
Use the System.Web.Optimization file included in the package in your references.
To update other packages:
Tools menu -> Library Package Manager -> Manage NuGet Packages for Solution.
Create a new MVC 4 RC internet application and run it. Navigate to Login which uses the same code
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
What allows Login.cshtml to work is the the Views\Web.config file (not the app root version) contains
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
Why is your Create view not working and Login is?
Import System.Web.Optimization on top of your razor view as follows:
#using System.Web.Optimization
I ran into this problem, however while running the command:
Install-Package -IncludePrerelease Microsoft.AspNet.Web.Optimization
I received the cryptic message (gotta love a great pun before the first cup of coffee):
Install-Package : The specified cryptographic algorithm is not
supported on this platform.
I am running this on Windows XP SP3 (not by choice) and what I found was that I had to follow the instructions posted by the user artsnob on the ASP.NET Forum
Please uninstall the Nuget and try re-installing it. If you are unable to do this, login as an Administrator.
Go to Tools=> Extension Manager => Select "Nuget Package Manager" => UnInstall
Install it again, by searching "Nuget" => Install.
If it did not work, please try installing, 1.7.x version as I mentioned in the previous post (It doesn't mean, you have to use the previous version, if it works fine, we can report this bug, and get the patches for the latest version).
Once I ran this I could then run the command line to update the Web.Optimization.
Hope this saves someone some digging.
Just write
#section Scripts{
<script src="#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/jqueryval")"></script>
}
I upgraded from Beta to RC and faced 'Scripts' does not exist issue. Surfed all over the web and the final solution is what N40JPJ said plus another workaroudn:
Copy the following in View\Web.config :
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Helpers"/>
</namespaces>
and the following inside View\Shared_Layout.cshtml
#if (IsSectionDefined("scripts"))
{
#RenderSection("scripts", required: false)
}
Hope it helps.
Apparently you have created an 'Empty' project type without 'Scripts' folder.
My advice
-create a 'Basic' project type with full 'Scripts' folder.
With respect to all developers.
just remove/ hide the code from create & Edit razor view of your controller.
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
: remove view page.
: add namespace webconfig (in view directory)
: create view an try!
good luck...
One more for the pot - spent ages trying to work out the same problem - even though it was defined in the web.config for root and the root of Views. Turns out I'd mistakenly added it to the <system.web><pages><namespaces>, and not <system.web**.webPages.razor**><pages><namespaces> element.
Really easy to miss that!
When I enter on a page that haves this code:
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
This error occurs: Error. An error occurred while processing your request.
And this exception are recorded on my logs:
System.Web.HttpException (0x80004005): The controller for path '/bundles/jqueryval' was not found or does not implement IController.
em System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
...
I have tried all tips on this page and none of them solved for me. So I have looked on my Packages folder and noticed that I have two versions for System.Web.Optmization.dll:
Microsoft.AspNet.Web.Optimization.1.1.0 (v1.1.30515.0 - 68,7KB)
Microsoft.Web.Optimization.1.0.0-beta
(v1.0.0.0 - 304KB)
My project was referencing to the older beta version. I only changed the reference to the newer version (69KB) and eveything worked fine.
I think it might help someone.
That has an obvious solution. I had the same problem later. Not related to Assembly References or ... .It'll occur In hierarchy calling of MVC Partial views, when you have complicated page structures. So calling/rendering each part separately on each page (maybe a master page or partial) will cause to not see required parts of page like the bellow code :
#RenderSection("Scripts", required: false)
That simply forces page to find and render related section and in case of failure shows you an error message like you.
So I suggest you to trace your pages (like program trace) from master to all of its partials to Detect Dependencies. Maybe it be a terrible work, but no other choices available here.
Not that according to my experience, some conditional situations in programming causes not to show you the right error causes the problem.
I had this issue after I added an Area to a project that didn't have any.
To get rid of it just copied the web.config withing root Views folder to the Views folder of the area and it started working.
For me this solved the problem, in NuGet package manager console write following:
update-package microsoft.aspnet.mvc -reinstall
When i started using MVC4 recently i faced the above issue while creating a project with the empty templates.
Steps to fix the issue.
Goto TOOLS --> Library Package Manager --> Packager Manager Console
Paste the below command and press enter
Install-Package Microsoft.AspNet.Web.Optimization
Note: wait for successful installation.
Goto Web.Config file in root level and add below namespace in pages namespace section.
add <namespace="System.Web.Optimization" />
Goto Web.Config in Views folder and follow the step 2.
Build the solution and run.
The Package mentioned in step 1 will add few system libraries into the solution references like System.Web.Optimization is not a default reference for empty templates in MVC4.
I hope this helps.
Thank you
I had a very similar error when upgrading a project from MVC3 to MVC4.
Compiler Error Message: CS0103: The name [blah] does not exist in the
current context
In my case, I had outdated version numbers in several of my Web.Configs.
I needed to update the System.Web.Mvc version number from "3.0.0.0" to "4.0.0.0" in every Web.Config in my project.
I needed to update all of my System.Web.WebPages, System.Web.Helpers, and System.Web.Razor version numbers from "1.0.0.0" to "2.0.0.0" in every Web.Config in my project.
Ex:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
...
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
Be sure to review the Web.Configs in each of your Views directories.
You can read more about Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4.
If you added to your web.config and it still shows message, then you need to close your project and reopen it, now it will exist and #Styles.Render("") and #Scripts.Render() will work fine.
I solve this problem in MvcMusicStore by add this part of code in _Layout.cshtml
#if (IsSectionDefined("scripts"))
{
#RenderSection("scripts", required: false)
}
and remove this code from Edit.cshtml
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
Try this:
#section Scripts
{
Scripts.Render("~/bundles/jqueryval") // <- without ampersand at the begin
}

Why don't my Html Helpers have intellisense?

I can't get intellisense for my own html helpers. My CustomHtmlHelpers.cs looks like this:
using System.Web.Mvc;
using System.Text;
using System.Web;
namespace laget.Web.Helpers
{
public static class CustomHtmlHelpers
{
//MY HELPERS
}
}
and in my Web.config:
<pages>
<namespaces>
<add namespace="laget.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
<add namespace="System.Web.Helpers" />
</namespaces>
</pages>
If I put <#using laget.Web.Helpers> in my view, I get the intellisense issue fixed.
Should it not be enough with the code in Web.config?
Sometimes it doesn't seem to work right away. Try closing the .cshtml file, and re-opening it. Then if that doesn't work, try restarting Visual Studio. Also make sure you actually compiled your project, intellisense won't work with non-compiled helpers.
I'm pretty sure that you're not editing the correct Web.config file.
You need to add your namespace to the one in your Views directory.
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="laget.Web.Helpers" />
</namespaces>
</pages>
</system.web.webPages.razor>
You actually don't need to restart Visual Studio in most cases. All you need to do is close the .cshtml file and reopen it!
It needs it on the local page. I'm pretty sure this has to do with Namespace resolution. It isn't exactly sure what you are referring to without the local using statement.
I ran into this today as well. Sometimes just closing the Razor view's window in Visual Studio and re-opening it will do the trick without having to do a full Visual Studio restart.
I tried to solve an issue like this one yesterday. I had e pre-compiled dll (project name ie: MyHtmlHelpers) containing helpers and lot of other classes.
I had the assembly referenced in the web project and the all "standard"-helpers showed up in intellisense but, even though I added the namespace to both web.config in the root and in the views-folder nothing worked. When running the project helpers works, but not in intellisense.
I added a new class and wrote a new html helper inside the web project, added the namespace to web.config. And that worked.
After some hours add tried my last card, adding the MyHtmlHelpers-project to the same solution as my webproject. That did the trick. I diden't change anything in the configs just added the project to the same solution and changed the reference to point at the project insted of the compiled dll.
Isen't that strange? A VS-bug?
I found that i was adding the reference to the wrong web.config. It's not the main config but the web.config in the views directory...
So now I will show you the steps
1.Create or open an existing class library project (if you open an existing one be sure to remove the MVC5 nuget package)
2.Add the MVC (5.0) nuget package (
right click project in solution explorer -> Manage NuGet Packages -> search for MVC and install “Microsoft ASP.NET MVC”)
3.Close any and all open .cshtml files
4.Right click project -> Properties -> Build -> change Output path to your project “bin/”
5.Add the following minimal Web.config to the root of your class library project
( the web config file is solely needed for intellisense. Configuration (via Web.config)
should be done in the WebApplication hosting your ClassLibrary assembly)
6.Clean and Build the solution.
7.Open cshtml file and try now :)
I found that if it still doesn't work, you may need to go to the properties of the custom class and change the build action from "content" to "compile". That resolved it for me.
I try all of this solutions, one more thing which i didnt find is that in root web.config i must change webpages:Version from 2.0.0.0 to 3.0.0.0.
Open and close all .cshtml files and it's worked.
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />

MvcSiteMap Provider Setup Problems

In relation to this post I'm using the MvcSiteMap provider. I can't seem to get it to work. What I'm doing is opening the project made available by the download, compiling it, then taking the MvcSiteMap.Core.dll generated by the build, placing it in my Dependencies folder in my MVC project, and then right-clicking on references and hitting "Add Reference". From here I'm just trying to use it in my masterpage but intellisense isn't picking it up, and trying to build with it isn't working either.
I'm trying to do <%=Html.SiteMapPath()%> without any luck. Any ideas?
Have you add <add namespace="name of the mvcsitemap package"> to yours web.config (under following xpath: /configuration/system.web/pages/namespace)?
Here is an example from the project home page: http://mvcsitemap.codeplex.com/
<pages>
<controls>
<! -- ... -->
</controls>
<namespaces>
<! -- ... -->
<add namespace="MvcSiteMap.Core.Helpers"/>
</namespaces>
</pages>

Resources