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

HELP: Translate ASP.net WebForm engine syntax to Razor engine syntax.

2 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Saleem
Top achievements
Rank 1
Saleem asked on 21 Nov 2010, 03:29 PM
I am wondering if any one can help me to translate demo at http://demos.telerik.com/aspnet-mvc/tabstrip from ASP.net WebForm engine to Razor syntax.

<% Html.Telerik().TabStrip()
            .Name("TabStrip")
            .Items(tabstrip =>
            {
                tabstrip.Add()
                    .Text("ASP.NET MVC")
                    .ImageUrl("~/Content/Common/Icons/Suites/mvc.png")
                    .Content(() =>
                    {%>
                        <ul>
                            <li>Pure ASP.NET MVC components</li>
                            <li>Completely Open Source</li>
                            <li>Exceptional Performance</li>
                            <li>Based on jQuery</li>
                            <li>Search Engine Optimized</li>
                            <li>Cross-browser support</li>
                        </ul>
                    <%});
            })
            .SelectedIndex(0)
            .Render();
    %>

example is embedding HTML inside <% and %> markers. How we can do this using Razor engine.

Thanks,
-Saleem

2 Answers, 1 is accepted

Sort by
0
nachid
Top achievements
Rank 1
answered on 21 Nov 2010, 06:03 PM
someone posted here the whole project translated to Razor
I can't remember exactly his name but it was around two weeks ago

UPDATE
http://mvcdemo.chiplex.com/
0
Accepted
Mike Kidder
Top achievements
Rank 1
answered on 24 Nov 2010, 10:23 PM
Saleem,

As nachid mentioned, the converted Razor web demo site is a good resource.   In case it goes down, here is the conversion.  

UPDATE:
Looks like the above mentioned razor demo is missing the <text> .. </text> elements in the tabstrip demo code view tab.  The following works...

UPDATE#2:
Hey, learned something new.  The demo works because there is no line-spacing/line-break between the @ and first the <ul> tag on the inner razor block.  So you can ditch the <text> .. </text> if you want and still get intellisense... :)

@(Html.Telerik().TabStrip()
            .Name("TabStrip")
            .Items(tabstrip =>
            {
                tabstrip.Add()
                    .Text("ASP.NET MVC")
                    .ImageUrl("~/Content/Common/Icons/Suites/mvc.png")
                    .Content(@<text>
                        <ul>
                            <li>Pure ASP.NET MVC components</li>
                            <li>Completely Open Source</li>
                            <li>Exceptional Performance</li>
                            <li>Based on jQuery</li>
                            <li>Search Engine Optimized</li>
                            <li>Cross-browser support</li>
                        </ul>
                    </text>);
            })
            .SelectedIndex(0)
)

The razor wrapped syntax @(  ... ) outer block allows you break up Telerik's fluent on multiple lines.   The inner @<text> ... </text> outputs a string value, one of the three overloads for .Content() method.    The advantage of using the razor syntax vs. a string literal of @" ... " in that method is that you get Intellisense for that inner code block.  Nice......
Tags
General Discussions
Asked by
Saleem
Top achievements
Rank 1
Answers by
nachid
Top achievements
Rank 1
Mike Kidder
Top achievements
Rank 1
Share this question
or