0

Ive got this function as a html helper which should write a javascript function onto the page, I then call this in the masterpage like this <%Html.RenderBaseUrlScript(); %>

My problem is that the script never seems to be written to the page, I search in the source and cannot see it anywhere, I have tried moving this around from the head to the body of the html masterpage, Im really confused as to why this is not workung, please help public static string RenderBaseUrlScript(this HtmlHelper helper) {

        return string.Format("<script type='text/javascript'> $.url=function(url){{return '{0}'+url;}}", GetBaseUri());


    }
1
  • Perhaps a 'helper', rather than a 'melper'? Commented Jun 14, 2010 at 23:01

1 Answer 1

1

Try:

<%= Html.RenderBaseUrlScript() %>

Notice the = sign and no semicolon. Since your html helper method is not writing anything directly to the response stream (which is good), you need to actually call Response.Write() on the output of your function. The <%= %> tags are short form for Response.Write().

If your helper method was writing directly to the response stream itself, your code would be working. But it's much better to have it this way.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.