我正在使用John爸爸单页应用程序源代码来创建我自己的应用程序,在使用Breeze时遇到了一些问题。我有自己的简易控制器,一旦我添加了第二个HttpGET方法,就会得到“找到与请求匹配的多个操作”的错误。
这是奇怪的,因为在他的代码中,他添加了多个GET,他的代码可以工作,但我想我遗漏了一些东西。
风控制器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Breeze.WebApi;
using AgencyUpdate.Models;
namespace AgencyUpdate.Controllers
{
[BreezeController]
public class BreezeController : ApiController
{
readonly EFContextProvider<AgencyDbContext> _ContextProvider =
new EFContextProvider<AgencyDbContext>();
public string MetaData()
{
return _ContextProvider.Metadata();
}
[HttpGet]
public IQueryable<api_Agency> GetAgency()
{
return _ContextProvider.Context.api_Agency;
}
[HttpGet]
public IQueryable<api_AgencyOffice> GetOffice()
{
return _ContextProvider.Context.api_AgencyOffice;
}
}
}我使用这个URL请求数据:
**http://localhost:13762/api/breeze/GetAgency**另外,我找到了这个用于路由的.CS文件,但我不知道是否需要对它进行更改。
BreezeWebApiConfig
using System.Web.Http;
[assembly: WebActivator.PreApplicationStartMethod(
typeof(AgencyUpdate.App_Start.BreezeWebApiConfig), "RegisterBreezePreStart")]
namespace AgencyUpdate.App_Start {
///<summary>
/// Inserts the Breeze Web API controller route at the front of all Web API routes
///</summary>
///<remarks>
/// This class is discovered and run during startup; see
/// http://blogs.msdn.com/b/davidebb/archive/2010/10/11/light-up-your-nupacks-with-startup-code-and-webactivator.aspx
///</remarks>
public static class BreezeWebApiConfig {
public static void RegisterBreezePreStart() {
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "BreezeApi",
routeTemplate: "breeze/{controller}/{action}"
);
}
}
}有人知道问题出在哪里吗?
发布于 2013-07-29 10:15:06
我觉得有点傻,我需要使用的URL是风/风/方法名。
John的代码在URL中没有两次使用微风,因此出现了混乱
发布于 2014-04-24 16:38:56
爸爸的课程有一个单页的应用程序-jumpstart.zip文件与项目源代码的章节。BreezeWebApiConfig.cs内容的正确版本如下:
public static class BreezeWebApiConfig {
public static void RegisterBreezePreStart() {
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "BreezeApi",
routeTemplate: "api/{controller}/{action}"
);
}
}
}注意字符串routeTemplate:“api/{控制器}/{action}”
https://stackoverflow.com/questions/17920999
复制相似问题