[英]The resource cannot be found error in web API MVC 4
My web api looks working and it dispalys data in json format 我的网络API看起来可以正常工作,并且以JSON格式显示数据
http://localhost:60783/api/employee/GetEmployeeList/
but when i try to point out the .cshtm file then it gives me : 但是当我尝试指出.cshtm文件时,它给了我:
The resource cannot be found error .
my routeConfig looks like this 我的routeConfig看起来像这样
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
And my webApiConfig : 还有我的webApiConfig:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
my Global.asax : 我的Global.asax:
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
I have controller called EmployeeController
i amcalling the api using 我有一个名为
EmployeeController
控制器,我正在使用api
public async Task<ActionResult> Index()
{
HttpResponseMessage response = await ServiceAccess.Get("Employee/GetEmployeeList", null);
if (response.IsSuccessStatusCode)
{
List<Employee> model = await ServiceAccess.DeserializeAs<List<Employee>>(response);
return View(model);
}
return Content("No Record");
}
public ActionResult EmployeeList()
{
return View();
}
service Access class : 服务访问类别:
public static HttpClient httpClient;
static ServiceAccess()
{
httpClient = new HttpClient();
httpClient.BaseAddress = GeneralConstants.ServiceBaseURI;
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async Task<T> DeserializeAs<T>(HttpResponseMessage SerializedResponse)
{
return JsonConvert.DeserializeObject<T>(await SerializedResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
}
//mis named the name should be GetMany
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async Task<HttpResponseMessage> GetAll(string uri)
{
HttpResponseMessage response = await httpClient.GetAsync(uri).ConfigureAwait(false);
return response;
}
and web config file has this 和Web配置文件有这个
<add key="ServiceBaseURI" value="http://localhost:60783/api/" />
the lnk which gives me problem : 给我问题的lnk:
http://localhost:60783/Employee/EmployeeList/
Any help appreciated. 任何帮助表示赞赏。
There are few bug in your code. 您的代码中几乎没有错误。 If you consider and debug your code you will get the answer.
如果您考虑并调试代码,您将得到答案。
EmployeeController
and MVC controller name EmployeeController
is same. EmployeeController
和MVC控制器名称EmployeeController
是相同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.