This is a migrated thread and some comments may be shown as answers.

[Solved] Open external url in new window

1 Answer 58 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Johan
Top achievements
Rank 1
Johan asked on 27 Jan 2012, 10:30 AM
Hi,

I am pretty new to both asp.net mvc and telerik extensions for asp.net mvc, so please bear with me...

I have a site with a navigation menu where most of the links are local and I use ".Action" to redirect to the views.
However I do have one link that is external, i.e. another site on the Internet, and would like to open that url in a new window.
Can this be done?

This is the part of the code in the ".cshtml" file that holds the menu:

<div class="menu_search">
    @if (HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Html.Telerik().Menu().HtmlAttributes(new { Visible = "true" })
       .Name("Mainmenu").Orientation(MenuOrientation.Horizontal)
       .Items(menu =>
       {
           menu.Add()
               .Text("Home")
               .ImageUrl("~/Content/Common/Icons/Suites/mvc.png")
               .HtmlAttributes(new { style = "width: 100px;" })
               .Action("Index", "Home");
           menu.Add()
               .Text("My Reports")
               .HtmlAttributes(new { style = "width: 160px;" })
               .ImageUrl("~/Content/Common/Icons/Suites/ajax.png")
               .Action("Index", "Reports");
           menu.Add()
               .Text("Search")
               .HtmlAttributes(new { style = "width: 120px;" })
               .ImageUrl("~/Content/Common/Icons/Suites/sitefinity.png")
               .Url("http://www.google.com");
       })
       .Render();
    }
</div>

1 Answer, 1 is accepted

Sort by
0
Muhammad
Top achievements
Rank 1
answered on 25 Apr 2012, 04:43 PM

Add .LinkHtmlAttributes(new {target="_blank"}) for menu item

                menu.Add()

               .Text("Home")
               .ImageUrl("~/Content/Common/Icons/Suites/mvc.png")
               .HtmlAttributes(new { style = "width: 100px;" })
               .Action("Index", "Home")

                     .LinkHtmlAttributes(

 

new {target="_blank"});

 

Tags
Menu
Asked by
Johan
Top achievements
Rank 1
Answers by
Muhammad
Top achievements
Rank 1
Share this question
or