Ayarlanacak 2. kısım.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace WebApplication2 { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } }
Temiz gelen (yukarıdaki gibi) RouteConfig için, “route” ‘ları tek tek buradan yönlendirmek yerine
routes.MapMvcAttributeRoutes();
ile “controller” ‘ımız içinde yazacağımız “attribute” ‘a dönüştürerek burada daha sonra meydana gelecek olan karmaşıklığı önlemiş oluruz.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace WebApplication2 { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); //BURADAN controller'a yönlendirme olur routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } }
kullanacağımız “controller” içinde yönleneceğimiz “ActionResult” ‘a “attribute” olarak ekleriz.
[Route("pers/liste/{gelenDegisken}")] public ActionResult personeller(string gelenDegisken) { return Content(gelenDegisken); //"Content()" ile sayfaya deneme amaçlı olarak string şeklinde döndürdüm }
Temiz kod.