I am working on a MVC3 application.
In my view I am using @Html.ActionLink for anchor links. Every thing working fine. But those links are including the current url's params in the link.
If my current link is http://localhost:25466/Blog/all/2
Action link being generated are http://localhost:25466/Blog/Blog/shoes/2
In the above link actually I am not doing any thing to include '2' in the url. But still it is being added.
My route config are
routes.MapRoute(
"Blog", "Blog/Blog/{tag}/{id}",
new { controller = "Blog", action = "Blog", tag = UrlParameter.Optional,id="1" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = "1" },
constraints: new { id = @"\d+" }
);
And my actions are
public ActionResult All(int id)
{
var context = new BlogCore.DbContext.BlogContext();
var list = context.Get(id,20);
return View(list);
}
public ActionResult Blog(string tag,int id)
{
var context = new BlogCore.DbContext.BlogContext();
var list = context.Get(HttpUtility.UrlEncode(tag), id, 20);
return View("All", list);
}
And this is how I am using actionlink to generate anchor link
@Html.ActionLink(blog.PostTitle, "Blog", "Blog", new { tag = blog.PostRewriteName }, null)
How can I avoid 2 in the action link.
Thanks in advance.