我一直在試圖實現大衛海登的果園CMS和ASP .NET Web API http://www.davidhayden.me/blog/orchard-cms-and-asp.net-web-api,但我遇到了問題,基本上得到一個頁面找不到。果園cms apicontroller,返回xml
這是我有:
在我的控制器
ContactViewModel.cs
namespace Sunkist.ContactManager.Controllers
{
public class ContactsController : ApiController
{
private readonly IContentManager _contentManager;
public ContactsController(IContentManager contentManager)
{
_contentManager = contentManager;
}
public IEnumerable<ContactViewModel> Get()
{
return _contentManager
.Query(VersionOptions.Published, "Contact")
.List()
.Select(c => new ContactViewModel(c));
}
public ContactViewModel Get(int id)
{
var contact = _contentManager.Get(id);
if (contact == null)
throw new HttpResponseException
(new HttpResponseMessage(HttpStatusCode.NotFound));
return new ContactViewModel(contact);
}
}
}
視圖模型文件夾 ViewModel.cs
namespace Sunkist.ContactManager.ViewModel
{
public class ContactViewModel
{
private Orchard.ContentManagement.ContentItem c;
public ContactViewModel(Orchard.ContentManagement.ContentItem c)
{
// TODO: Complete member initialization
this.c = c;
}
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
}
}
和遷移
namespace Sunkist.ContactManager {
public class Migrations : DataMigrationImpl {
public int Create() {
// Creating table ContactRecord
SchemaBuilder.CreateTable("ContactRecord", table => table
.ContentPartRecord()
.Column("Name", DbType.String)
.Column("Address", DbType.String)
.Column("City", DbType.String)
);
return 1;
}
}
}
我是新來的果園和.Net MVC,所以我不知道我在做什麼錯了?
你會得到一個404,當你去哪裏? –
當我嘗試點擊該頁面時:http:// localhost:30321/OrchardLocal/api/sunkist.contactmanager/contacts – jmorrissette
您確定這是您的操作的正確網址嗎?您是否創建了自定義路線? 「api」部分來自哪裏?根據您鏈接的文章,如果您創建了該路線,它應該是/ api/contacts。 –