Monday, 13 February 2012

ASP.NET MVC: Adding active tag for html elements

 public static MvcHtmlString SelectedLink(this HtmlHelper helper, string linkText, string actionName, string controlName, string activeClassName, int id)
{
if (helper.ViewContext.RouteData.Values["action"].ToString() == actionName &&
helper.ViewContext.RouteData.Values["controller"].ToString() == controlName)
return helper.ActionLink(linkText, actionName, controlName, new { Class = activeClassName, Id = id });

return helper.ActionLink(linkText, actionName, controlName);
}
or 
 
        public static MvcHtmlString ActiveMenuItem(this HtmlHelper helper, string linkText, string actionName, string controllerName, int id)
{
TagBuilder li = new TagBuilder("li");

RouteData routedata = helper.ViewContext.RouteData;
string currentAction = routedata.GetRequiredString("action");
string currentController = routedata.GetRequiredString("controller");
int currentId = ConvertionHelper.GetConvertedValue<int>(routedata.GetRequiredString("id"));

if (string.Equals(currentAction, actionName, StringComparison.OrdinalIgnoreCase) &&
string.Equals(currentController, controllerName, StringComparison.OrdinalIgnoreCase) &&
int.Equals(currentId, id))
{
li.AddCssClass("active");
}

li.InnerHtml = helper.ActionLink(linkText, actionName, new { Id = id }).ToHtmlString();

return MvcHtmlString.Create(li.ToString());
}

Thursday, 9 February 2012

Areas duplicated: Multiple types were found that match the controller named 'Home'.

Problem:

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Home' has found the following matching controllers:
Project.Web.Controllers.HomeController
Project.Web.Areas.Dashboard.Controllers.HomeController

Solution:

In Global.asax

    routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Project.Web.Controllers" }
);

Tuesday, 24 January 2012

The Web.config file is read-only

[IisWebSiteSequence] [ERROR] [10/17/2007 11:38:22 AM]: Access to the path 'C:\Inetpub\wwwroot\wss\VirtualDirectories\5003\web.config' is denied.

Network service and Network must have ‘write’ permisson.

Thursday, 19 January 2012

SharePoint 2010 installation error: "The language of this installation package is not supported by your system"

 
1. OfficeServer.exe /extract:c:\SP2010
2.In Config.xml 
Add: <Setting Id="AllowWindowsClientInstall" Value="True"/>

Monday, 5 December 2011

Could not load file or assembly “xxx.dll", PublicKeyToken=null” or one of its dependencies. The system cannot find the file specified in .NET 4.0

After we virtualized a production machine and booted this virtualized machine, .NET reported some errors after re-registering .NET 4.0 on IIS7 these error where resolved, but one WCF service kept on logging the error:

Could not load file or assembly ‘App_Web_squ1ikqu, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.

Solution

The error was resolved after stopping all application pools in IIS7 and deleting the temporary internet files in the following folders:

    C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files

http://www.roelvanlisdonk.nl/?p=2081