Click here to Skip to main content
Rate this: bad
good
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
   {      
       [HttpGet]
       public Guid GetID(string name)
       {
       }
    }
 
This is my site Action Controller.
 public class DemoViewController : Controller
    {   
       [HttpGet]   
        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
v2
Comments
JemiM at 29-Jan-13 9:00am
   
What you have tried?ActionLink?
karthikeyan.m21 at 29-Jan-13 9:18am
   
i tried to action link..
Rate this: bad
good
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
  Permalink  
Comments
karthikeyan.m21 at 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 at 29-Jan-13 10:04am
   
then use like this @Html.ActionLink("Admin", "Index", "Meets", new { area = "" }, null)
karthikeyan.m21 at 29-Jan-13 15:13pm
   
i need to call api controller in page load?
JemiM at 29-Jan-13 23:57pm
   
In MVC there is no pageLoad?Where you want to reDirect and From?
karthikeyan.m21 at 30-Jan-13 12:29pm
   
now i need to call server side to call api controller.
JemiM at 31-Jan-13 0:10am
   
Why you are implementing APIController in ApplicationController?
karthikeyan.m21 at 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 at 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 at 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
good
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
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
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