找不到浏览器/显示信息 [英] Can't find/display info in browser

查看:172
本文介绍了找不到浏览器/显示信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新建VS 2012 MVC应用,第一次做的RESTful API(目前<一个href=\"http://www.asp.net/web-api/tutorials/hands-on-labs/build-restful-apis-with-aspnet-web-api#Exercise3\"相对=nofollow>在本教程)这一点上,我似乎无法得到的信息在谷歌浏览器中正确显示。其设置断点,如图在我的控制器的get()函数的教程中,我知道它被调用,并在浏览器中检查网络视图时,的它看到我的两个条目,我试图显示

我的code是几乎相同的例子,用的标题切换出:

  @ {
    ViewBag.Title =指数;
    布局=〜/查看/共享/ _Layout.cshtml
}&LT; D​​IV ID =身体&GT;
    &所述;微升的id =drug_entries&GT;&下; / UL&GT;
&LT; / DIV&GT;@section脚本{
&LT;脚本类型=文/ JavaScript的&GT;
    $(函数()
    {
        $ .getJSON('/ API / DrugEntry',函数(drugEntriesJsonPayload)
        {
            $(drugEntriesJsonPayload)。每个(函数(I,项)
            {
                $('#drug_entries')追加。('&LT;立GT;'&GT; + item.NDC +'&LT; /李&GT;');
            });
        });
    });
&LT; / SCRIPT&GT;
}

任何想法可能是它没有看到什么原因?或者,如果有我可以提供更多的信息?谢谢!

我route.config:

  //&LT;自动生成/&GT;
使用系统;
使用System.Collections.Generic;
使用System.Diagnostics程序codeAnalysis。
使用System.Linq的;
使用的System.Web;
使用System.Web.Mvc;
使用System.Web.Routing;命名空间MedicationsShortagesDashboard
{
[ExcludeFrom codeCoverage]
公共类RouteConfig
{
    公共静态无效的RegisterRoutes(RouteCollection路线)
    {
        routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);        routes.MapRoute(
            名称:默认,
            网址:{控制器} / {行动} / {ID}
            默认:新{控制器=家,行动=索引,ID = UrlParameter.Optional}
        );
    }
}
}

我WebApiConfig.cs:

  //&LT;自动生成/&GT;
使用系统;
使用System.Collections.Generic;
使用System.Diagnostics程序codeAnalysis。
使用System.Linq的;
使用System.Web.Http;命名空间MedicationsShortagesDashboard
{
    [ExcludeFrom codeCoverage]
    公共静态类WebApiConfig
    {
        公共静态无效的注册(HttpConfiguration配置)
        {
            config.Routes.MapHttpRoute(
                名称:DefaultApi
                routeTemplate:API / {}控制器/(编号),
                默认:新{ID = RouteParameter.Optional}
            );            //取消注释code以下行来启用带有一个IQueryable或IQueryable的&LT操作的查询的支持; T&GT;返回类型。
            //为了避免处理意外或恶意的查询,请使用QueryableAttribute验证设置,以验证传入查询。
            //欲了解更多信息,请访问http://go.microsoft.com/fwlink/?LinkId=279712。
            //config.EnableQuerySupport();            //要禁用应用程序中的跟踪,请注释掉或删除code的下面一行
            //欲了解更多信息,请访问:http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();
        }
    }
}


解决方案

在您的WebApiConfig.cs添加此

 使用System.Net.Http.Headers;
使用System.Web.Http;命名空间XXX
{
    公共静态类WebApiConfig
    {
        公共静态无效的注册(HttpConfiguration配置)
        {
            //公约为基础的路由。
            config.Routes.MapHttpRoute(
                名称:DefaultApi
                routeTemplate:API / {}控制器/(编号)
            );
        }
    }
}

New to VS 2012 MVC applications, first time doing RESTful API (currently at this point in the tutorial) and I can't seem to get info to properly display in Google Chrome. Having set breakpoints as shown in the tutorial in my Controller's Get() function, I know it is being called, and when checking the Network View in the browser, it sees both of my entries I'm trying to display.

My code is practically identical to the example, with titles switched out:

@{
    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>
}

Any idea what might be the cause of it not seeing anything? Or if there's more information I can provide? Thanks!

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

My 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();
        }
    }
}

解决方案

Add this in your WebApiConfig.cs

using System.Net.Http.Headers;
using System.Web.Http;

namespace XXX
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Convention-based routing.
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}"
            );
        }
    }
}

这篇关于找不到浏览器/显示信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆