I am creating an Orchard module where i want to add a WebApi controller.
My Module.txt:
Name: ModuleName
AntiForgery: enabled
Author: The Orchard Team
Website: http://orchardproject.net
Version: 1.0
OrchardVersion: 1.0
Description: Description for the module
Features:
ModuleName:
Description: Description for feature ModuleName.
I have added an ApiRoutes class:
using Orchard.Mvc.Routes;
using Orchard.WebApi.Routes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
namespace ModuleName
{
public class ModuleNameApiRoutes : IHttpRouteProvider
{
public void GetRoutes(ICollection<RouteDescriptor> routes)
{
foreach (var routeDescriptor in GetRoutes())
{
routes.Add(routeDescriptor);
}
}
public IEnumerable<RouteDescriptor> GetRoutes()
{
return new[] {
new HttpRouteDescriptor {
Name = "ModuleName",
Priority = 5,
RouteTemplate = "api/modulename/{controller}/{id}",
Defaults = new {
area = "ModuleName",
id = RouteParameter.Optional
}
}
};
}
}
}
Then i have added an apicontroller:
using Newtonsoft.Json.Linq;
using Orchard;
using Orchard.Data;
using ModuleName.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace ModuleName.Controllers
{
public class ConsumptionController : ApiController
{
public IOrchardServices Services { get; private set; }
private readonly IRepository<Vessel_ConsumptionPartRecord> _repository;
public ConsumptionController(IOrchardServices orchardServices,IRepository<Vessel_ConsumptionPartRecord> repository)
{
_repository = repository;
}
// GET: Home
public HttpResponseMessage Get()
{
...
}
}
}
I am on Localhost and the home url is:
http://localhost:30321/OrchardLocal
When i go to
http://localhost:30321/OrchardLocal/api/ModuleName/Consumption
I get a Not Found page.
Can anyone shed some light?
Your GET method does not have a parameter id. That might be it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With