Html.ActionLink, Url.ActionLink and Html.RouteLink return empty urls, even though the target url is valid and displayed properly from url?
I played around with the route but, it keeps return empty url without any exception.
Html.ActionLink, Url.ActionLink and Html.RouteLink return empty urls, even though the target url is valid and displayed properly from url?
I played around with the route but, it keeps return empty url without any exception.
I have the same problem when upgrading my project from mvc2 to mvc3. The problem was in old global.asax file, that I put into new project.
So when I replaced old .asax onto new, actionLinks start to work properly.
Global.asax for mvc3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace RealtyMVC
{
public class MvcApplication : System.Web.HttpApplication
{
//!!!add this method
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
//!!!and add this call
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
}