protected override object CreateModel( ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { ValueProviderResult result; result = bindingContext.ValueProvider.GetValue("RouteUrl"); if (result == null) { throw new NotImplementedException("RouteUrl must be specified"); } foreach (Type item in RP.GetPageTypesReprository()) { if (result.AttemptedValue == SF.GetTypeRouteUrl(item)) { var model = Activator.CreateInstance(item); bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, item); return(model); } } throw new NotImplementedException("RouteUrl must be specified"); }
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" }); routes.MapRoute("ImagesThumbnail", "Image", new { controller = "Images", action = "GetImage" }); routes.MapRoute("Captcha", "Image", new { controller = "Captcha", action = "Get" }); //generic URLs routes.MapGenericPathRoute("GenericUrl", "{generic_se_name}", new { controller = "Error", action = "Error404" }, new[] { "Uco.Controllers" }); //main site page routes.MapRoute( name: "HomePage", url: "", defaults: new { controller = "Page", action = "DomainPage", name = "root" }, namespaces: new string[] { "Uco.Controllers" } ); //Uco.dll pages foreach (Type item in RP.GetPageTypesReprository()) { routes.MapRoute( name: item.Name, url: SF.GetTypeRouteUrl(item) + "/{name}", defaults: new { controller = "Page", action = item.Name }, namespaces: new string[] { "Uco.Controllers" } ); routes.MapRoute( name: item.Name + "_Lang", url: "{lang}/" + SF.GetTypeRouteUrl(item) + "/{name}", defaults: new { controller = "Page", action = item.Name }, namespaces: new string[] { "Uco.Controllers" } ); } //if (SF.UsePlugins()) //{ //plugin dll pages //foreach (Type item in RP.GetPlugingsAbstractPageChildClasses()) //{ // string PageTypeName = item.Name; // string PluginNamespace = item.Namespace.Replace(".Models", ""); // routes.MapRoute( // name: PageTypeName, // url: SF.GetTypeRouteUrl(item) + "/{name}", // defaults: new { controller = "Page", action = PageTypeName }, // namespaces: new string[] { PluginNamespace + ".Controllers" } // ); // routes.MapRoute( // name: PageTypeName + "_Lang", // url: "{lang}/" + SF.GetTypeRouteUrl(item) + "/{name}", // defaults: new { controller = "Page", action = PageTypeName }, // namespaces: new string[] { PluginNamespace + ".Controllers" } // ); //} ////plugin dll data //foreach (string item in RP.GetPluginsReprository()) //{ // string Namespace = item + ".Controllers"; // routes.MapRoute( // name: Namespace, // url: item + "/{controller}/{action}/{id}", // defaults: new { id = UrlParameter.Optional }, // namespaces: new string[] { Namespace } // ); // routes.MapRoute( // name: "lang_" + Namespace, // url: "{lang}/" + item + "/{controller}/{action}/{id}", // defaults: new { id = UrlParameter.Optional }, // namespaces: new string[] { Namespace } // ); //} //} //Uco.dll data routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { id = UrlParameter.Optional }, namespaces: new string[] { "Uco.Controllers" } ); routes.MapRoute( name: "Default_Lang", url: "{lang}/{controller}/{action}/{id}", defaults: new { id = UrlParameter.Optional }, namespaces: new string[] { "Uco.Controllers" } ); }