Asp.net 函数在Orchard CMS中不返回json数据
我有一个现有的ASP.NETMVC5项目,带有FluentNHibernate和WebAPI。为了使用Orchard CMS,我将其包含在Orchard模块中,但我遇到的问题是我的view Policy_Lookup.cshtml中,我的函数没有重新运行数据,我不知道为什么。在Google Ghrome控制台中,它向我显示了加载资源失败的错误:服务器响应的状态为404未找到http:/localhost:30321/api/VinSearch/getVinResults?VinNum=jt4rn50r9e009467&Agency=09207 这是我的Policy_Lookup.cshtml文件: 这是控制器文件中的操作:Asp.net 函数在Orchard CMS中不返回json数据,asp.net,json,orchardcms,Asp.net,Json,Orchardcms,我有一个现有的ASP.NETMVC5项目,带有FluentNHibernate和WebAPI。为了使用Orchard CMS,我将其包含在Orchard模块中,但我遇到的问题是我的view Policy_Lookup.cshtml中,我的函数没有重新运行数据,我不知道为什么。在Google Ghrome控制台中,它向我显示了加载资源失败的错误:服务器响应的状态为404未找到http:/localhost:30321/api/VinSearch/getVinResults?VinNum=jt4rn
public List<VINResult> getVinResults(String VinNum, String Agency)
{
return dbh.GetVinToVinResult(VinNum, Agency);
}
注意:当我运行该项目时,编译器没有达到此函数Orchard中的路由是在IRouteProvider的实现中声明的,甚至WebAPI路由也是如此。您的注册方法可能从未被命中。有关Orchard中WebAPI实现的详细信息,请参阅。能否显示为该模板提供服务的路由定义和控制器操作?当然可以,我编辑了帖子,以便您可以查看路由定义和控制器操作。此外,当我仅在浏览器中测试功能时,我会收到一个错误HTTP错误404.0-未找到您正在查找的资源已被删除、名称已更改或暂时不可用。。请注意,这个项目在没有Orchard CMS的情况下工作得非常好,我在将它集成到Orchard模块时遇到了这个错误。您的意思肯定是调试器没有达到这个代码。您正在使用的URL是什么?错误消息提到/api/VinSearch/getVinResults,您定义了路由OIS_New。实际上,调试器没有达到代码要求,我不知道为什么,我是orchard的初学者,我肯定错过了什么,或者我在某个地方犯了错误。我在没有Orchard CMS的项目中使用了这个url/api/VinSearch/getVinResults,但当我想使用Orchard时,它不起作用:我以前尝试过,但没有任何变化。非常感谢您的评论:请用您尝试过的内容更新问题,准确无误。
public IEnumerable<RouteDescriptor> GetRoutes()
{
return new[] {
new RouteDescriptor {
Priority = 5,
Route = new Route(
"OIS_New",
new RouteValueDictionary {
{"area", "OIS_New"},
{"controller", "Home"},
{"action", "Policy_Lookup"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "OIS_New"}
},
new MvcRouteHandler())
}
};
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace OIS_New
{
public class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
config.Formatters.Remove(config.Formatters.XmlFormatter);//to set json response as a default display
// Web API routes
config.MapHttpAttributeRoutes();
//to configure the routing convention
config.Routes.MapHttpRoute(
name: "VinSearch",
routeTemplate: "api/{controller}/{action}/{VinNum}/{Agency}",
defaults: new { VinNum = RouteParameter.Optional, Agency = RouteParameter.Optional }
);
config.EnsureInitialized();
}
}
}
public List<VINResult> getVinResults(String VinNum, String Agency)
{
return dbh.GetVinToVinResult(VinNum, Agency);
}