views:

30

answers:

1

I have an HTML Helper that essentially renders static content read from HTML files (inside of a vdir). There are cases when the HTML file has a title element defined and in such cases, the current page should use the given title. The content inside of the body should be rendered where the Helper class is referenced in the View.

This is how I call the helper.

            <%=Html.StaticContent("staticcontent.htm", 
                                new List<StaticContentTag>()
                                  {
                                      new StaticContentTag()
                                      {TagKey=ReplaceTags.MarketName,
                                      TagValue = "Austin"}
                                  }, Model, true) %>

I'm passing in the ViewModel so that I can set the title and the last parameter is a flag that says whether to force the title or not.

The head has the title defined like this.

    <title><%=Model.Title%></title> 

I know what I'm doing wrong here by referencing the Model.Title element before even calling the helper. Any ideas on how I can work around this?

+1  A: 

i believe ur title tag is rendered before u call the html helper in ur view. the purpose of helpers is to render html tags where they are called not to change contents of already rendered tags that can be done through javascript. however i would not use all that new keywords in my view. rather i would make a view model containing all required information for the view and then i would have no problem writing statement

<title><%=Model.title%></title>
Muhammad Adeel Zahid
What you said is correct Muhammad. The Title gets rendered before the helper HTML does. This is preliminary code I'm testing out. I promise I will move all of that init code into a ViewModel :) I do need some ideas on how I can push the Title. JS maybe?
Praveen
using js u can write document.title = "<%=Model.title%>" in onload event
Muhammad Adeel Zahid