Razor output not working in MVC 3 but working in MVC 2

This same code working fine with MVC 2 but not working in MVC 3 Razor. Once page is loaded not loading menu from HTMLHelper called within Razor like below.

Hardcoded menu for testing which is not outputting on the page.

using System.Collections.Generic; using System.Web.Mvc; using System.Web.Mvc.Html; using myproject.Extensions; public static class MenuHelper { public static string TabbedMenu(this HtmlHelper helper, IEnumerable<MenuTab> tabs) { //I have hard coded menu for testing purpose. return "<div class='menu-image'><img src='/content/Images/common/on-left.gif' alt='' /></div><div class='on'><a class='over' href='/?Length=4'>Home</a></div><div class='menu-image'><img src='/content/Images/common/on-right.gif' alt='' /></div><a href='/Home/About'>About</a><a href='/Home/Contact'>Contact</a>"; } }

Below is Razor CSHTML code.

@{Html.TabbedMenu ( new List<MenuTab> { MenuTab.Create("Home", "Index", "Home"), MenuTab.Create("About", "About", "Home"), MenuTab.Create("Contact", "Contact", "Home") } );}

-------------Problems Reply------------

Wrapping code in @{ ... } (like you did) is Razor's equivalent to <% ... %> (without an =).

Therefore, your code calls the function, but doesn't do anything with the result.

You should remove the {} and the ; and simply write @Html.TabbedMenu(...); this is equivalent to <%: Html.TabbedMenu(...) %>.

You'll also need to change the method to return an HtmlString to prevent Razor from escaping the HTML.

Category:razor Views:0 Time:2010-11-26
Tags: razor

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.065 (s). 11 q(s)