Razor view ASP.NET Core MVC, a method using Html.Raw native output html

We ASP.NET Core MVC project, there is a Razor view file Index.cshtml, as follows:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <h1>Index</h1>
    @{ 
        string name = "Demo label";
        int value = 1000;
    }
    <div>
        @{ 
            ( "$ this.Write < div > : the Name {name} </ div > ;") after the // output to the front end of the page, is not native html syntax, "<" and ">" to the escape "& lt;" and "& gt; "
             this.Write (Html.Raw ($ " < div > the name: {name} </ div > ")); // output to the front page, would be native html syntax of

             this .write ($ '\ R & lt \ n-"); 

            this.Write ($" < div > the value: {value} </ div > "); // output to the front page, html syntax is not native," < "and"> "to escape after the" & lt; "和">"
            this.Write(Html.Raw($"<div>The Value: {value} </ div > ")); // output to the front page, would be native html syntax
         }
     </ div > 
</ body > 
</ html >

Run the view, the following page:

Therefore, in the method using Html.Raw Razor view html syntax can be output to the front page of the original.

 

Guess you like

Origin www.cnblogs.com/OpenCoder/p/11199390.html