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.

1

1 Answer 1

1

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

@Html.Raw(HttpUtility.HtmlDecode(Model.FullName));
Sign up to request clarification or add additional context in comments.

1 Comment

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

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.