I am building a Site using ASP.NET MVC. In RouteConfig
, I modified the method like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{Director}/{Movie}/{id}",
defaults: new { controller = "Movies", action = "Index", id = UrlParameter.Optional, Director = UrlParameter.Optional, Movie = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Movies", action = "Create", id = UrlParameter.Optional }
);
}
And in IndexView, I coded like:
@model IEnumerable<MvcMovie.Models.Director>
<table>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
</tr>
<tr>
<td>
@foreach (var movie in item.Movies)
{
<div style="width: 100%;">
@Html.ActionLink(movie.Title, "Index", new { Director = movie.Director.Name, Movie = movie.Title }, null)
</div>
}
</td>
</tr>
}
</table>
Actually I modified RouteConfig
because I want different URLs for different directors and different movies in order to satisfy our client's SEO requirement
.
It is working fine for the Index
Action but even when I tried to invoke Create
action using @Html.ActionLink("Create New", "Create")
, it still invokes Index
action. According to my understanding so far, it should invoke Create
Action. I am new to MVC so sorry if my question seems foolish. But what major thing, I am missing here?
@Html.ActionLink("Create New", "Create")
- this will generates a url. While hovering with the mouse, you can see it at the bottom of the browser. Can you please share the url generated ? – VeeKayBee Jun 18 '13 at 5:52http://localhost:<portnmber>/<cntrollername>/create
. The mentioned url will always point to default route that is index action will be fired always. – VeeKayBee Jun 18 '13 at 5:57