c# - HtmlHelper.Button(..., string onClickMethod, ...) HTML-encodes single-quotes! -
i'm upgrading old project mvc 1.0 mvc 3.0 (yes, it's old), , i've run issue calling htmlhelper.button(..., onclickmethod, ...) html-encodes single quotes '
i can see how not issue if onclickmethod name of method called in javascript, how using it:
return helper.button(name, buttontext, htmlbuttontype.button, string.format("window.location='{0}'", url));
which broken.
is there way bypass encoding? can see hacking changing return type of method string, , doing:
return string.format(helper.button(name, buttontext, htmlbuttontype.button, "window.location={0}").tostring(), "'" + url + "'");
but more or less hack, , not elegant.
having '
should work. though document stream contains encoded value browser unencodes when builds dom. can use dom inspection tool see yourself.
if put following on page see alert box fine upon click:
<input type="button" onclick="alert('hello');" />
Comments
Post a Comment