In ASP.NET MVC, I'm trying to create a link that includes an anchor tag (i.e., directing the user to a page, and a specific section of the page).
The URL I am trying to create should look like the following:
<a href="/category/subcategory/1#section12">Title for a section on the page</a>
My routing is set up with the standard:
routes.MapRoute("Default", "{controller}/{action}/{categoryid}");
The action link syntax that I am using is:
<%foreach (Category parent in ViewData.Model) { %>
<h3><%=parent.Name %></h3>
<ul>
<%foreach (Category child in parent.SubCategories) { %>
<li><%=Html.ActionLink<CategoryController>(x => x.Subcategory(parent.ID), child.Name) %></li>
<%} %>
</ul>
<%} %>
My controller method is as follows:
public ActionResult Subcategory(int categoryID)
{
//return itemList
return View(itemList);
}
The above correctly returns a URL as follows:
<a href="/category/subcategory/1">Title for a section on the page</a>
What I can't figure out is how to add the #section12 part. The "section" word is just the convention I am using to break up the page sections, and the 12 is the ID of the subcategory, i.e., child.ID.
Any help is appreciated.