Dresel / RouteLocalization

RouteLocalization is an MVC and Web API package that allows localization of your attribute routes.
MIT License
67 stars 13 forks source link

Routes without Localization #57

Closed JobaDiniz closed 7 years ago

JobaDiniz commented 8 years ago

It seems that is not possible to have routes without localization once you add a localization for any route. (using attribute routing)

My controller without setting up localization for it.

[RoutePrefix("payment")]
public class Payment : Controller
{
  [Route("continue/paypal", Name="PaypalRedirect")]
  public ActionResult RedirectPaypal() { ....}
}

In my WebApi, I'm trying to build a link to that action: var url = Url.Link("PaypalRedirect", null); However, url is alway null.

But, once I add a localization for that route, and write var url = Url.Link("PaypalRedirect", new {culture = "en-US"}); it works, the generated url is right.

How I can fix this?

Dresel commented 8 years ago

So if I understand you correctly, you want to generate a neutral (non-localized) route?

Neutral route only exists by default if you use AddAsNeutralRoute, AddAsNeutralAndDefaultCultureRoute or AddAsNeutralRouteAndReplaceByFirstTranslation for AttributeRouteProcessing.

If there is no neutral route, you can add it manually via AddNeutralTranslation.

localization.AddNeutralTranslationForNamedRoute("PaypalRedirect");

Does this help / work for you?

You may also post your RouteLocalization setup.

JobaDiniz commented 8 years ago

localization.AddNeutralTranslationForNamedRoute("PaypalRedirect"); it worked.