The below line appears in one of my javascript files, what would be the syntax for it in Razor.
var initialData = <%= new JavaScriptSerializer().Serialize(Model) %>;
Razor syntax is a simple programming syntax for embedding server-based code in a web page. In a web page that uses the Razor syntax, there are two kinds of content: client content and server code.
cshtml is just a file extension. razor view engine is used to convert razor pages(. cshtml) to html.
Cshtml is basically razor view extension and any view renders in html finally. You need to use Razor in your application as it supports server side code but raw html does not.
cshtml file indicates that the file is a Razor Page.
Like this:
@Html.Raw(new JavaScriptSerializer().Serialize(Model))
The Html.Raw
call is necessary to prevent it from being HTML-escaped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With