首页 > 代码库 > Razor视图

Razor视图

@{

  string name="jerry";
}

<div> @name </div>     //显示jerry

 

 

 

@{

  string js="<script>alert(‘a‘)</script>";
}

<div> @js</div>     //显示<script>alert(‘a‘)</script>而并非弹出alert

 

 

 

@{

  string js="<script>alert(‘a‘)</script>";
}

<div> @Html.Raw(js)</div>     //弹出alert        Html.Raw(string/object)   将字符串当作html进行解析

 

 

@{

  ViewBag.Name = "abc";

}

<script type="text/javascript">
  $(function () {
    var msg = "hello,@ViewBag.Name";
    $("#abc").html(msg).show("slow");   //显示hello,abc
  });
</script>

 

Razor视图