views:

239

answers:

0

I'm trying to use donut-caching on the Site.Master page for things like the User Login and Shopping Cart, so that we can put OutputCache on some of the more resource intensive pages in our app.

Currently, I'm using the tag and then writing out the html from the static method in the code behind.

      <asp:Substitution ID="Substitution1" runat="server" MethodName="RenderUserLogin"/>

    public static string RenderUserLogin( HttpContext incomingContext )
    {

        System.Text.StringBuilder osb = new System.Text.StringBuilder();

        osb.Append( "<p>" );
        if ( incomingContext.User.Identity.IsAuthenticated 
            && !string.IsNullOrEmpty( incomingContext.User.Identity.Name ) )
        {
            osb.Append( "Hi, <span class=\"name\">" );
            osb.Append( "<a href=\"/Users/Show\">" );

           // ... etc. ...

       return osb.ToString();

    }

I'd rather have the html code in a partial view (.ascx) and render that out to a string, because I really don't like having specific html elements that are used by javascript buried in compiled code.

I've looked at this post which looks like it's a valid idea and could be modified to render the partial to a string: Render Partial through Controller

Are there any cleaner ways to render a partial to a string without having to go through a controller?