What is wrong with my routing in my MVC4 mobile app?

I just deployed the MVC4.NET 4.0 application for my web host, for "detailed" testing. Non -aretic routes work fine, for example. my

@Html.ActionLink("Register as a Client", "Register", "Account", new { registrationType = "Client"}, null) 

the link works fine, and the link opens the correct page. However, with reference to an area-based action, for example:

 @Html.ActionLink("Authors", "Index", "Home", new { Area = "Author", registrationType = "Author" }, null) 

the link actually displayed in the browser is missing an action and controller, i.e.

 http://mylivedomain.com/?Area=Author&registrationType=Author 

It may be worth noting that the css MVC4 linking function did not work after deployment, and I returned to using classic-style links in separate style sheets.

MAYBE RELATED: My question is: Why is the unmodified template code in my MVC4 application trying to double-register areas?

JUST IN: Removing the default action from the default route route mappings for Runet solved this problem. There was no default controller in the VS2012 template template.

+5
asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing asp.net-mvc-areas
Jul 17 '12 at 21:19
source share
5 answers

Try checking this.ControllerContext.RouteData.DataTokens ["area"] in the action methods of your area.

I had a situation with a similar problem in which the area name was an empty string.

Setting a DataToken in an action method may give you a quick fix, but it does not answer the question of why MVC does not specify a scope name.

+2
Jul 20 2018-12-12T00:
source share

In your case, since you specify the area in the query string, the routes from Global.asax.cs should be applied. I believe you have something like this:

  public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ).DataTokens.Add("area","Author"); } 

This code makes the default Home / Index route and skips the Home / Index in the url . If you change controller = "Home" to something else, for example, controller = "Home2", you will see the full link for Home / Index and the new default route Home2 / Index. Similar apply to default routes in areas if you specify them.

+2
Jul 25 '12 at 6:25
source share

In your global.asax.cs file, make sure you have this line in Application_Start :

 AreaRegistration.RegisterAllAreas(); 

In each area, you should have AreaRegistration.cs something like this:

 public class testAreaRegistration : AreaRegistration { public override string AreaName { get { return "test"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "test_default", "test/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); } } 
+1
Jul 25 2018-12-12T00:
source share

Using @ Html.ActionLink

use this format

 @Html.ActionLink("Authors", "Index", "Home", new { Area = "Author", registrationType = "Author" }, new{}) 

Solved my problem.

+1
Oct 17
source share

Do you accidentally inherit PortableAreaRegistration from MvcContrib in any of your areas?

We had exactly the same symptoms (working locally, not on the server) until we removed all PortableAreaRegistrations from Portable Areas and returned to using just AreaRegistration, since MVC4 can register a portable region without any additional libraries.

0
Nov 13 '12 at 21:45
source share



All Articles