You can read the ref and take a look in the Difference between ApiController and Controller in ASP.NET MVC, since people are commonly confused with them.
Questions tagged [asp.net-apicontroller]
456 questions
0
votes
2 answers
Web API GetAsync not working on localhost
I am learning how to connect to a ASP.NET Web API service using Visual Studio 2012 on my localhost.
Here is the sample Web API Controller:
namespace ProductStore.Controllers
{
public class ProductsController : ApiController
{
static readonly…

user2985419
- 553
- 3
- 9
- 23
0
votes
1 answer
.NET MVC4 - Return different subset of fields from Model in the same API controller action
I have a model and an action in a WebAPI controller
public class MyModel
{
public ClassA ObjA { get; set; }
public ClassB ObjB { get; set; }
public ClassC ObjC { get; set; }
}
and the action:
[HttpGet]
public MyModel GetMyModel()
{
…

MFK
- 77
- 3
- 7
0
votes
1 answer
How to access a web service implemented by ApiController with [Authorize]
I am writing a client site C# program, I want to access a web service implemented by ApiController with [Authorize].
the server side code is like:
[Authorize]
public class EventsController : ApiController
{
[ActionName("Default")]
…

rockXrock
- 3,403
- 1
- 25
- 18
0
votes
1 answer
Set HttpResponseMessage headers from within the Get method of my controller
I have a REST service using Web API 2.0 and MVC 5. My controller derives from EntitySetController. I have a Get method that returns the resource as an IQueryable. My question is how do I access the HttpResponseMessage object from within the Get…

Saurabh
- 41
- 4
0
votes
1 answer
Resolving from Castle Windsor container in an API controller
I have an API controller that fires a service that uses constructor dependency injection. I would like to use the Windsor container to inject those dependencies, but I'm not sure the best practice.
Here's part of the API controller factory:
private…

Steven
- 303
- 3
- 11
0
votes
1 answer
API controller passed invalid JSON receives null
I'm using ASP.NET's ApiController class to create a Web API. I find that if I pass invalid JSON, instead of the caller getting a 500, the input parameter is null. As in, if I pass
{ "InputProperty:" "Some Value" }
which is clearly not valid, to…

Becca Dee
- 1,530
- 1
- 24
- 51
0
votes
1 answer
how can i get list of models from ajax to controller?
I have an apicontroller that returns List to success part of ajax function:
var inputdata = {
'InsPayInsuranceID': insPayInsuranceID
, 'InstallmentDistance': installmentDistance
, 'InsPayNumber': insPayNumber
,…

mortazavi
- 401
- 9
- 22
0
votes
1 answer
Ajax call with query string to Asp.net Web Api
I call api as
$.getJSON("/api/accapi/1?p=5&min=10&max=20" , function (json) {
...
});
and my ApiController
public class AccApiController : ApiController
{
// GET api/accapi
public string GetAccApi(string id)
{
return id;
…

Melih
- 323
- 3
- 11
0
votes
1 answer
Sending POST in JSON to ApiController
Edit: Found the answer (in comments).
Currently, I am using System.Web.Http.ApiController to access some object in the memory of a server. These objects can have any type.
I use the following api controller to receive them:
(example code. Not the…

luz
- 113
- 2
- 7
0
votes
2 answers
Multiple actions in asp.net controller api
Hello People I have 2 methods inside in my controller api:
[HttpPost]
[HttpGet]
public IEnumerable Get(HotelSearch hotelSearch)
{
try
{
if (hotelSearch == null)
{
hotelSearch = new HotelSearch
…

mcamara
- 731
- 4
- 15
- 26
0
votes
1 answer
System.InvalidOperationException when getting a List with an ApiController
When I visit the /WeedAPI/ URL in my application, I get the following error. How do I get my web API working? (Controller, model code to follow)
Full error detail:
An error has occurred.
…

Jonathan Wilson
- 4,138
- 1
- 24
- 36
0
votes
1 answer
WP site, ASP.net Web API ApiController
We are building our public facing website on Wordpress and on a Linux server. The user will be logging into the WordPress site with OAuth2. Our data and API is going to be built on an ASP.net MVC4 server. I have a couple of problems that I need to…

Codersjunto
- 31
- 3
0
votes
1 answer
How to pass JSON object throught the REST URL
I Have a method GetCustomerDetails in WEBUI controller(below)
public bool GetCustomerDetails(string customer)
{
Uri CustUri = null;
HttpClient client = new HttpClient();
client.BaseAddress = new…

user2522503
- 178
- 3
- 12
-1
votes
1 answer
Migrating from NewtonSoft.Json to System.Text.json
We have an POST endpoint which accepts dictionary as request body.
public class A {
public IDictionary? Values { get; set; };
}
Earlier we were accepting JToken. We have replaced JToken with JsonElement during…

Byresh P
- 21
- 4
-1
votes
1 answer
URL.Link(routeName, value) returns Null in the case of Controller level Route attribute
If I use Route attribute with template [controller] then no problem it return values. But if I use my own template, it returns null for other actions except currently executing action. Please see below code (I have added…

Power Star
- 1,724
- 2
- 13
- 25