开发者

Cannot display text returned from a static function in asp.net

I'm following the tutorial located at: http://www.asp.net/learn/mvc/tutorial-20-cs.aspx

I created my own .Menu() method to return a string of menu items. No matter what I do, I can't get my menu items to appear. If I set a breakpoint at the return of the .Menu() method and copy it's results to the correct location in Site.Master, everything looks fine. It's returning the correct string, it's just not displaying them.

I even tried creating a simpler method:

public static string Test(this HtmlHelper helper)
{
    return ("Test!");
}

And usi开发者_开发百科ng it here:

    <div id="title">
        <h1>My MVC Application <%Html.Test(); %></h1>            
    </div>

But this text never appears on my page. Any idea what I'm doing wrong?


Using the <% %> syntax will call the function but ignore its return value.

You need to write <%= Html.Test() %> (Note = and lack of ;) to write the return value of the Test function to the page. Note also that since it's not a standalone statement, it must not have a semicolon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜