I am trying to build a language switcher inside the navbar.
My code is the following (in _LoginPartial.cshtml
)
using ( Html.BeginForm( "SetCulture", "Home", FormMethod.Post ) ) {
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<img src="@selectedImgSrc" alt="@culture" />
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li role="presentation"><a href="#" class="language" rel="it-IT"><img src="~/assets/images/i18n/it-IT.png" alt="Italiano" /></a></li>
<li role="presentation"><a href="#" class="language" rel="en-US"><img src="~/assets/images/i18n/en-US.png" alt="English" /></a></li>
</ul>
</li>
</ul>
}
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink( "Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" } )</li>
<li>@Html.ActionLink( "Sign in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" } )</li>
</ul>
@selectedImgSrc
value is ~/assets/images/i18n/en-US.png
@culture value
is en-us
However this code produce the following result
Which has a couple of problems:
- On the nav the image is not showed but only the text (en-US)
- The dropdown is too large and I dont like it. Is there any way to make it smaller?