I have only route. It is configured like :
routes.MapRoute(
name: "Default",
url: "{lang}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", lang = "en", id = UrlParameter.Optional },
constraints: new { lang=new LanguageConstraint()
}
);
I'm creating link using
<a href='@Url.Action("Index", "Results", new { lang=System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName}')</a>
but link is not cerated at all. What I'm doing wrong? It seems fine. I have Index action and Results controller. It is ok when I have default route MVC comes with {controller}/{action}
This is LanguageConstraint:
public class LanguageConstraint : IRouteConstraint
{
public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (routeDirection == RouteDirection.IncomingRequest)
{
string language = values["lang"].ToString(); //(en|hr|de|it|fr|sk|nl|hu|sv|pl|cs|ru|sl
if (language == "en" || language == "hr" || language == "de" || language == "it" || language == "fr" || language == "sk" || language == "nl" ||
language == "hu" || language == "sv" || language == "pl" || language == "cs" || language == "ru" || language == "sl" )
return true;
else
return false;
}
return false;
}
}
LanguageConstraintis you own class? Can you provide it in question?<a href='@Url.Action("Index", "Results", new { lang = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName })'></a>languagewhen you are in debug mode? Or it isn't go there?