0

I am trying to Set a textfields values as Raw Html so that it does not encode strings containing characters like single quotes. e.g. O'Riely is displayed as O & # 0 3 9 ; Riely.
The problem i have is I cannot use @html.Raw() function in the Javascript when I also reference a view Model field/mix up with c# code.

<script type="text/javascript">
    $(document).ready(function () {
         <text>
        $('#mytextField').val('@Model.FullName ');
        </text>
    });
</script>

Any Suggestion will be more then welcome.

hussian
  • 399
  • 6
  • 19
  • possible duplicate of [Display encoded html with razor](http://stackoverflow.com/questions/5029264/display-encoded-html-with-razor) – Codeman Feb 11 '15 at 22:13

1 Answers1

1

As answered in this question, you can do this with Html.Raw:

@Html.Raw(HttpUtility.HtmlDecode(Model.FullName));
Community
  • 1
  • 1
Codeman
  • 12,157
  • 10
  • 53
  • 91
  • My string(@Model.FullName) is not encoded However when its rendered on the page it shows as encoded html. Another issue is that I am doing it in JQuery document.load and calling something like html.Raw ends in Jquery Error. Uncaught SyntaxError: Unexpected identifier – hussian Feb 12 '15 at 09:39