VS 2012 MVC應用程序的新手,第一次使用RESTful API(目前爲at this point in the tutorial),我似乎無法獲取在Chrome瀏覽器中正確顯示的信息。教程在我的控制器的get()函數,我知道它被調用,並檢查網絡視圖在瀏覽器中,it sees both of my entries I'm trying to display在瀏覽器中找不到/顯示信息
我的代碼實際上是相同的例子,有標題,當切換出:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="body">
<ul id="drug_entries"></ul>
</div>
@section scripts{
<script type="text/javascript">
$(function()
{
$.getJSON('/api/DrugEntry', function (drugEntriesJsonPayload)
{
$(drugEntriesJsonPayload).each(function (i, item)
{
$('#drug_entries').append('<li>' > + item.NDC + '</li>');
});
});
});
</script>
}
任何想法什麼可能是它沒有看到任何東西的原因?或者如果有更多的信息,我可以提供?謝謝!
我route.config:
// <auto-generated/>
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MedicationsShortagesDashboard
{
[ExcludeFromCodeCoverage]
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
我WebApiConfig.cs:
// <auto-generated/>
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Web.Http;
namespace MedicationsShortagesDashboard
{
[ExcludeFromCodeCoverage]
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
//config.EnableQuerySupport();
// To disable tracing in your application, please comment out or remove the following line of code
// For more information, refer to: http://www.asp.net/web-api
config.EnableSystemDiagnosticsTracing();
}
}
}
是的,你可以向我們提供您的路線.config,還是你沒有配置它? –
我還沒有,在這裏,可能錯過了一步? http://pastebin.com/SQ56A1BC – Befall