【问题标题】:The resource cannot be found error in web API MVC 4 Masterpage LayoutWeb API MVC 4 Masterpage Layout中的资源找不到错误
【发布时间】:2017-06-29 14:23:17
【问题描述】:

Web api 看起来工作正常,它以 json 格式显示数据

http://localhost:55304/api/InsuranceCompanyRegistration

我的 routeConfig 如下所示:

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:

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

我的控制器呼叫:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DoctorsAndMedicines_Client.Controllers
{
    public class InsuranceCompanyRegistrationController : Controller
    {
        //
        // GET: /InsuranceCompanyRegistration/

        public ActionResult Index()
        {
            return View();
        }

    }
}

【问题讨论】:

  • 你能给我们看一下错误截图吗?
  • @Ciwan 请看我的截图
  • 在你的 Controller 类之上,你是否设置了路由属性?也向我们展示您的控制器代码。
  • @Ciwan 控制器类更新
  • @Ciwan 请查收

标签: asp.net-mvc asp.net-mvc-4 asp.net-web-api model-view-controller


【解决方案1】:

尝试将您的控制器从 InsuranceCompanyRegisterationController 重命名为 HomeController

【讨论】:

  • 导致此错误的 URL 是什么?
  • 找不到资源。
  • @IvinRaj 我编辑了答案,看看,告诉我你得到了什么?
猜你喜欢
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 2014-12-15
  • 2012-11-21
  • 1970-01-01
  • 2019-06-21
  • 2012-03-06
  • 2018-01-03
相关资源
最近更新 更多