Click here to Skip to main content
11,924,800 members (55,275 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET MVC
Hi All,
I'm working on an MVC4 Web API project that has site controllers and API controllers. How do I send a request to an API controller from one of the site controllers?

This is my REST API Controller.
public class ApplicationsController : ApiController
       public Guid GetID(string name)
This is my site Action Controller.
 public class DemoViewController : Controller
        public ActionResult GetID()
            return View();
Above Site action Controller is to used inside the Areas and My API Controllers to be used out side of Areas
Posted 29-Jan-13 3:40am
Edited 29-Jan-13 4:46am
JemiM 29-Jan-13 9:00am
What you have tried?ActionLink?
karthikeyan.m21 29-Jan-13 9:18am
i tried to action link..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Please specify the area in your ActionLink like below
@Html.ActionLink("Admin", "Index", "Meets", new { area = "Admin" }, null)

Hope this helps
karthikeyan.m21 29-Jan-13 9:49am
@jemi, my APIControllers are used out side of Areas. now how to send the request from areas site action controller.
JemiM 29-Jan-13 10:04am
then use like this @Html.ActionLink("Admin", "Index", "Meets", new { area = "" }, null)
karthikeyan.m21 29-Jan-13 15:13pm
i need to call api controller in page load?
JemiM 29-Jan-13 23:57pm
In MVC there is no pageLoad?Where you want to reDirect and From?
karthikeyan.m21 30-Jan-13 12:29pm
now i need to call server side to call api controller.
JemiM 31-Jan-13 0:10am
Why you are implementing APIController in ApplicationController?
karthikeyan.m21 31-Jan-13 1:27am
actually my project environment is all DB Access methods in APIController, we are using several Areas, each areas Controller to call APIController to Access the methods.
JemiM 31-Jan-13 3:47am
Please change your current architecture level of coding by implemting Repository pattern and dependency injection.Now you are keeping your dataAccessLayer in APIController.Please avoid this and implementing Repository pattern.
JemiM 31-Jan-13 3:51am
You can reuse the common methods in APIContoller for other controllers by implementing it. Keep Dataacesslayer separate from Controller.Don't mix up those things.Controller is only for handing the request and response
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Try this.
You can call an action outside in the Area
@Html.ActionLink("GetId", "Application", new { area = "" }) 

Call action inside of an area

@Html.ActionLink("GetId", "Api", new { area = "SpecifyYourAreaName" }) 
Hope this helps

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 | Mobile
Web03 | 2.8.151125.3 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2015
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