Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor Syntax Equivalent

Tags:

razor

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) %>;
like image 408
Richard Tasker Avatar asked Feb 25 '11 17:02

Richard Tasker


People also ask

What is the Razor syntax?

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.

Is Cshtml the same as Razor?

cshtml is just a file extension. razor view engine is used to convert razor pages(. cshtml) to html.

Is Cshtml the same as 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.

Is Cshtml a Razor page?

cshtml file indicates that the file is a Razor Page.


1 Answers

Like this:

@Html.Raw(new JavaScriptSerializer().Serialize(Model))

The Html.Raw call is necessary to prevent it from being HTML-escaped.

like image 172
SLaks Avatar answered Sep 22 '22 06:09

SLaks