Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:37:55+00:00 2026-05-28T00:37:55+00:00

I started to learn MVC and in conjunction want to use the KnockOut.js I

  • 0

I started to learn MVC and in conjunction want to use the KnockOut.js

I am having trouble understanding why the new @ include tag encodes everything to HTML(edit: ok i know now to prevent XSS).. but even worse how to stop it from doing that..

I have this code.

@{
    ViewBag.Title = "Home Page";
    var myData = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model);
}

<script type="text/javascript">
    var initialData =  @myData ;

Which produces this source

<script type="text/javascript">

var initialData =  [{&quot;Title&quot;:&quot;Tall Hat&quot;,&quot;Price&quot;:49.95},{&quot;Title&quot;:&quot;Long Cloak&quot;,&quot;Price&quot;:78.25}] ;

Ok. so tried using HttpUtility.HtmlDecode.. and nothing happens on the included bit in the javascript because the razor engine is reencoding it? but if it use the encode then reecnodes the encodes html.. briallinat.

I cannot work out how to stop the encoding.

The msdn says use @: but that does not work in the javascript block, i even tried
@{ @:new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model);}

That just something wierd and causes other errors.

How should this be done in the MVC model?

In aspx using

var initialData = <%= new JavaScriptSerializer().Serialize(Model) %>;

works fine..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:37:55+00:00Added an answer on May 28, 2026 at 12:37 am

    Html.Raw(string) will write out your string in its raw, unencoded form. Provided your string is not encoded to begin with.

    code example as requested (?!?!)

    @{
        ViewBag.Title = "Home Page";
        var myData = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model);
    }
    
    <script type="text/javascript">
        var initialData =  @Html.Raw(myData) ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started to learn how to use action listeners. To my understanding it
i just started to learn struts(+spring) MVC, and I could use some explanation of
I recently started to learn how to use openCL to speed up some part
I just started to learn MVC and am trying to understand how it works.
I have just started to learn ASP.NET MVC. When comparing ASP.NET MVC with Web
To learn ASP.net I started building a todo web app(web forms not MVC), this
I've finally started to learn PHP and I quite have trouble with it. I
I have started to learn ASP.NET MVC, and at this time of studying I
I started to learn C recently. I use Code::Blocks with MinGW and Cygwin GCC.
I'm new to ASP.NET and have just starting to learn ASP.NET MVC 3. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.