jojacafe
8/11/2016 - 11:57 AM

Get url action route

Get url action route

--- RouteConfig ---
routes.MapRoute(
                name: "Property",
                url: "{lang}/{pageProperty}/{agencyName}/{propertyReference}/{urlSafeTitle}",
                constraints: new { lang = @"(\w{2})" },
                defaults: new { lang = ConfigurationManager.AppSettings["languageDefault"].ToString(), controller = "Property", action = "GetProperty"},
                namespaces: new string[] { "chilliIS.propertyMallorca.Web.Controllers" }
            );

--- Model ---
System.Web.Mvc.UrlHelper urlHelper = new System.Web.Mvc.UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);

string url = urlHelper.Action("GetProperty", "Property", new { pageProperty = Resources.LanguageResources.Url_Translate_Property, agencyName = p.Agency.Name.Replace(" ", "-"), propertyReference = p.AgentPropertyReference, urlSafeTitle = p.urlSafeTitle });