Our application is developed using asp.net MVC4 and using a web.site map file for navigation. What happens is web.site map is called even when the user is hitting the enter key and navigates to the first action in the web.site map file. Wondering if there is a way to stop calling web.site map file in MVC4?
Asked
Active
Viewed 38 times
0
-
Please show relevant code and rendered HTML. – CodeCaster Jan 07 '16 at 12:25
1 Answers
0
If I understand correctly, this behavior is happening because the first action is the default tab stop in your page, and clicking Enter
triggers the hyperlink.
You can get around this by adding the tabindex attribute to each hyperlink and setting its value to -1
. On most modern browsers, this prevents you from being able to tab to the hyperlink.
Just edit your /Views/Shared/DisplayTemplates/SiteMapNodeModel.cshtml
template and add the tabindex
attribute to each hyperlink.
@model MvcSiteMapProvider.Web.Html.Models.SiteMapNodeModel
@using System.Web.Mvc.Html
@using MvcSiteMapProvider.Web.Html.Models
@if (Model.IsCurrentNode && Model.SourceMetadata["HtmlHelper"].ToString() != "MvcSiteMapProvider.Web.Html.MenuHelper") {
<text>@Model.Title</text>
} else if (Model.IsClickable) {
if (string.IsNullOrEmpty(Model.Description))
{
<a href="@Model.Url" tabindex="-1">@Model.Title</a>
}
else
{
<a href="@Model.Url" tabindex="-1" title="@Model.Description">@Model.Title</a>
}
} else {
<text>@Model.Title</text>
}
On a side note, this behavior has nothing at all to do with the Web.sitemap
file (assuming this is what you are referring to).

Community
- 1
- 1

NightOwl888
- 55,572
- 24
- 139
- 212