Using Razor within JavaScript

后端 未结 12 2489
萌比男神i
萌比男神i 2020-11-22 04:12

Is it possible or is there a workaround to use Razor syntax within JavaScript that is in a view (cshtml)?

I am trying to add markers to a Google map...

12条回答
  •  执笔经年
    2020-11-22 05:08

    I finally found the solution (*.vbhtml):

    function razorsyntax() {
        /* Double */
        @(MvcHtmlString.Create("var szam =" & mydoublevariable & ";"))
        alert(szam);
    
        /* String */
        var str = '@stringvariable';
        alert(str);
    }
    

提交回复
热议问题