2015-05-19 11 views
5

Tôi đang tạo mô-đun Orchard nơi tôi muốn thêm bộ điều khiển WebApi.WebApi Tuyến trả về Không tìm thấy trong Mô-đun Orchard

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. 

Tôi đã thêm một lớp ApiRoutes:

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 
        } 
       } 
      }; 
     } 
    } 
} 

Sau đó, tôi đã thêm một 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() 
     { 

      ... 
     } 


    } 
} 

Tôi đang trên Localhost và url nhà riêng là:

http://localhost:30321/OrchardLocal

Khi tôi đi đến

http://localhost:30321/OrchardLocal/api/ModuleName/Consumption

tôi nhận được một trang Not Found.

Có ai có thể làm sáng tỏ không?

Trả lời

2

Phương thức GET của bạn không có id thông số. Đó có thể là số

+0

Bạn không thể tưởng tượng làm thế nào tôi cảm thấy cho thiếu đó. Cảm ơn đã giúp đỡ. –

+0

np, xảy ra với điều tốt nhất của chúng tôi! – ErMasca

Các vấn đề liên quan