New to the world of Web API and I can't seem to get any custom view to display. I've done the basics, made a method in my controller that seems to be linked corrected where I'm calling it. I'm more familiar with MVC so I'm wondering am I missing something basic here? The view always returns an error can't be accessed for me.
The ActionResult, in the generated HomeController:
[HttpGet]
public ActionResult SpotDetails()
{
ViewBag.Title = "Spot Details";
return View();
}
The link to call it in the menu:
<ul class="nav navbar-nav">
<li>@Html.ActionLink("SHOR //", "Index", "Home", new {area = ""}, null)</li>
<li>@Html.ActionLink("Index", "Index", "Home", new {area = ""}, null)</li>
<li>@Html.ActionLink("Spot Profile", "SpotDetails", "Home", new {area = ""}, null)</li>
<li>@Html.ActionLink("API", "Index", "Help", new {area = ""}, null)</li>
</ul>
I should say the links to the index and the api help pages work perfectly.
This is my RouteConfig in case it's at fault, I haven't touched it at all:
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 }
);
}
And finally my WebApiConfig:
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Edit - the error message when the link is clicked:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its >dependencies) could have been removed, had its name changed, or is temporarily >unavailable. Please review the following URL and make sure that it is spelled >correctly.
Requested URL: /Home/SpotDetails