Reputation: 1767
Sometimes my application generates URLs that look like http://localhost/?Area=
or http://localhost/SomeController?Area=
I don't currently have any areas defined in this project, and I have tried removing area registration from application startup.
The only answer I have found is to use <a href="Url.Action()">
URLs.
There must be a cleaner way of removing this. Manually removing this from the URLs seems to provide the exact same result, but I am unsure as to why this is coming up in the the first place.
How do I resolve this using the routing system? please note that i am using t4mvc to generate actionlinks not the default mvc actionlink helpers
Edit:
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
/// <summary>
/// Registers MVC Routing Collection.
/// </summary>
/// <param name="routes">The routes.</param>
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"secstdsrte",
"SecondaryStandards/{standardType}/{sampleid}",
MVC.Reports.SecondaryStandards(),
null,
new { standardType = new SecondaryStandardTypeConstraint()
}
);
routes.MapRoute(
"misaRoute",
"Misa",
MVC.Reports.MISA()
);
routes.MapRoute(
"outfallroute",
"Outfalls/{fromDate}/{toDate}",
MVC.Reports.Outfalls( ApplicationController.DefaultFromDate, ApplicationController.DefaultToDate),
null,
new
{
fromDate = new DateTimeConstraint(),
toDate = new DateTimeConstraint()
}
);
routes.MapRoute(
"offspecRoute",
"Offspec/{fromDate}/{toDate}",
MVC.Reports.OleOffspec(ApplicationController.DefaultFromDate, ApplicationController.DefaultToDate),
null,
new //route constraints
{
fromDate = new DateTimeConstraint(),
toDate = new DateTimeConstraint()
}
);
routes.MapRoute(
"searchRoute",
"Search",
MVC.Reports.Search()
);
routes.MapRoute(
"compareresultsroute",
"compare/{samplePoint}/{analysis}/{fromDate}/{toDate}",
MVC.Reports.CompareResults(null, null, null, ApplicationController.DefaultFromDate, ApplicationController.DefaultToDate),
null,
new
{
samplePoint = new SamplePointExistsConstraint(),
analysis = new AnalysisExistsConstraint(),
fromDate = new DateTimeConstraint(),
toDate = new DateTimeConstraint()
}
);
routes.MapRoute(
"reportsRoute",
"Reports/{samplePoint}/{fromDate}/{toDate}",
MVC.Reports.Results("", ApplicationController.DefaultFromDate, ApplicationController.DefaultToDate),
null,
new //route constraints
{
samplePoint = new SamplePointExistsConstraint(),
fromDate = new DateTimeConstraint(),
toDate = new DateTimeConstraint() }
);
routes.MapRoute(
"railcarsRoute",
"RailCars/{forDate}",
MVC.Reports.RailCars(ApplicationController.DefaultToDate),
null,
new { forDate = new DateTimeConstraint() }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new
{ controller = "Reports", action = "Index", id =UrlParameter.Optional } // Parameter defaults
);
}
/// <summary>
/// Returns boolean value indicating whether the application is currently in debug mode
/// </summary>
public static bool isDebugging
{
get
{
return HttpContext.Current != null && HttpContext.Current.IsDebuggingEnabled;
}
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
Upvotes: 3
Views: 1373
Reputation: 43203
This issue was previously discussed on T4MVC @Url.Action(MVC.Controller.Action()) Renders "?Area=" Parameter in QueryString.
In short, it's a bug in T4MVC when the site doesn't use areas. You can work around by deleting this line (around line 303):
result.RouteValueDictionary.Add("Area", area ?? "");
Upvotes: 1
Reputation: 93444
You are more than likely ending up calling the wrong overload of ActionLink. There's an overload that takes a RouteValueDictionary and people confuse it for html attributes (it looks similar).
@Html.ActionLink("Link", "Action", "Controller", new { id = 1 }, new { @css="myclass" })
if you're not specifying a route value, then use null.
@Html.ActionLink("Link", "Action", "Controller", null, new { @css="myclass" })
Upvotes: 1