Click here to Skip to main content
13,503,505 members
Rate this:
 
Please Sign up or sign in to vote.
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 14-Feb-17 3:54am
Updated 14-Feb-17 9:26am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

Try "/Manager/BuildingAdd/5"
  Permalink  
Comments
Karthik Bangalore 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.180417.1 | Last Updated 14 Feb 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100