1.NuGet安裝RazorJS插件
2.testRazor.js 文件:
代碼:
@{
String s="Razor測試!";
}
$(document).ready(function(){
alert("@s");
});
3.在index.cshtm頁面引用:
@Html.RazorJSInline("~/Scripts/testRazor.js") //把testRazor.js 文件所有內容嵌入到index.cshtm
或
@Html.RazorJSInclude("~/Scripts/testRazor.js") //<script></script>標簽屬性href鏈接上被RazorJS編譯的testRazor.js文件.
結果:
彈出對話,內容為:"Razor測試!";