0

I have an 100% javascript application inside my ASP.NET WebAPI project. This application consumes all the data from my API methods.

Now, I have been requested to create a simple portal built in Razor and HTML also inside my WebAPI project (so like a MVC project).

So I have created a folder under "Controllers" folder named "Portal" where Im placing all my portal exclusive controllers.

Here is the Controllers structure folders:

enter image description here

This is my Razor web application views structure:

enter image description here

So when I run the application I can see the Login page view (under "Account" folder). When I click my Login button, I call my CommonController (Portal) to render a Left menu but I get the error:

enter image description here

I guess because I have 2 CommonControllers, but 1 is for serving my javascript application and the other is for my Portal application.

The line in my Index.cshtml that calls the Common controllers is:

 <div class="page-header page-header-blue">
  @Html.Action("Header", "Common")
  <h1><i class="icon-bar-chart"></i> Dashboard</h1>
</div>

In my WebApiConfig.cs I have the following Web Api Route:

 config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}"
            );

So I don't know how to tell it that I want to call CommonController that is under "Portal" folder.

Any clue or advice on how to do this and the best practice?

UPDATE:

I have create other route for my Portal controllers:

 config.Routes.MapHttpRoute(
               name: "DefaultMvc",
               routeTemplate: "portal/{controller}/{action}"
           );

Seems to work but in my index.cshtml calls : @Html.Action("Header", "Common") how can I tell the action to call Portal Common and not just Common ?

10
  • possible duplicate of Web API route is ignored and processed by MVC Commented Nov 8, 2014 at 18:03
  • Read the solution of the possible duplicate but I dont get it.. Commented Nov 8, 2014 at 18:16
  • I have been thinking in better create another web project only for the portal application. Commented Nov 8, 2014 at 18:29
  • I believe it has something to do with my Q&A. It's about how URL routing module prioritizes routes Commented Nov 8, 2014 at 18:44
  • Matias how do you think if I create better a separate project? Both projects will use my shared business rules dll, service dll, etc. Commented Nov 8, 2014 at 18:47

1 Answer 1

1

I think you can use areas for your case.

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Billing_default",
        "Admin/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );
}

And you need update Application_Start method

protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

Area in MVC 5 with example - step by step

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.