I gave this in my site.master
<li><%= Html.ActionLink("Material", "Index", "Material")%></li>
But my link doesnt seem to get my material controller Index method… I have this in my global asax file,
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Material", action = "Index", id = "" }
);
}
My controller:
public class MaterialController : Controller
{
//
// GET: /Material/
Material material = new Material();
public ActionResult Index()
{
var materials = material.FindAllMaterials();
return View();
}
}
What am i doing wrong…. When i click the link i get error.. Any suggestion…
The resource cannot be found.
Dump question -> make sure you’ve saved/compiled. What hints that u didn’t do this, is that u have two routes with the same name (aka. Default). Compiler should error.
Secondly, try to manually goto that resource. Ie, goto http://localhost:/materials/index and see if that works. Of course, replace the localhost with whatever is the dev url of your site. If that works.. continue.
Thirdly, hover the mouse over the html anchor (aka. the a href) and see what is displayed in the browsers ‘status’ bar. It should list the resource url which that anchor will redirect you to. Does it say ‘http://localhost:/materials/index’ ??
basically, the code looks ok for the HTML.ActionLink .. but there’s a few other possible things that have happened to screw this up.