Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,
I want to use route attribute in area but i could not.

it's RouteConfig.cs

public class RouteConfig
   {
       public static void RegisterRoutes(RouteCollection routes)
       {
           routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
           routes.MapMvcAttributeRoutes();
           routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new[] {"OgrenciEvi.Controllers"}
           );

       }
   }



Area/Manager/UniversityController;

[RouteArea("Manager")]
   public class UniversityController : Controller
   {
       SiteContext db = new SiteContext();

       // GET: Manager/University

       [Route("BuildingAdd/{UniID?}")]
       public ActionResult BuildingAdd(int UniID)
       {
           ViewBag.UniList = new SelectList(db.University, "UniID", "UniName");
           return View();
       }

       [HttpPost]
       public ActionResult BuildingAdd(BuildingModel NewBuilding)
       {
           if (Request.Form["btnSave"] != null)
           {
               if (ModelState.IsValid)
               {
                   db.Building.Add(NewBuilding);
                   db.SaveChanges();
               }
           }

           return RedirectToAction("BuildingAdd", "University", new { uniid = NewBuilding.UniID});
       }
   }


BuildingApp page's url should be "/Manager/University/BuildingAdd/5" or "/Manager/University/BuildingAdd"

but I got "Source could not find" error.

What I have tried:

.................................................
Posted
Updated 14-Feb-17 9:26am

1 solution

Your RouteArea is overriding the default route config (the controller name) when you move from convention to attributed routing.

Try "/Manager/BuildingAdd/5"
 
Share this answer
 
Comments
Karthik_Mahalingam 14-Feb-17 22:58pm    
5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900