简体   繁体   English

剃刀javascript填充限制

[英]Razor javascript filling limit

I have some problem with javascript limit. 我对javascript限制有问题。 I am using Razor and filling javascript array with razor like this:` 我正在使用Razor并用剃刀填充javascript数组,如下所示:

var KriterAlanlariHtml = new Array();

@{
    int sayac = 0;
    string html = "";
    foreach (var group in Model.GrupDTO)
    {
         if (group != null && group.ListAreaDTO != null)
            {


                foreach (var area in group.ListAreaDTO)
                {
                    html = BuildHtmlTag(area);

                    <text>
                    KriterAlanlariHtml[@sayac] = "@MvcHtmlString.Create(html)";
                    </text>

                    sayac++;
                }

    }

}

}

` `

After this codes View.cshtml filling Javascript array with html codes. 在此代码之后,View.cshtml用html代码填充Javascript数组。 But I couldnt this array in JavaScript. 但是我无法在JavaScript中使用此数组。 Because of javascript limitations. 由于javascript的限制。 If I check the elements on Chrome, I am seeing like screenshot-1. 如果我检查Chrome上的元素,则会看到类似屏幕截图1的画面。

Screenshoot-1 屏幕截图-1

Screenshoot-2 屏幕截图2

I coulndt use like this code: KriterAlanlariHtml[25] .Chrome giving this error: KriterAlanlariHtml is not defined 我可以使用像这样的代码:KriterAlanlariHtml [25] .Chrome给出此错误: 未定义KriterAlanlariHtml

How can i solve this problem ? 我怎么解决这个问题 ? (HTML is not wrong.) (HTML没错。)

You need to add javascript code inside script tag, the updated code is below 您需要在script标签内添加javascript代码,更新后的代码如下

    <script>
    var KriterAlanlariHtml = new Array();
</script>

@{
    int sayac = 0;
    string html = "";
    foreach (var group in Model.GrupDTO)
    {
         if (group != null && group.ListAreaDTO != null)
            {
                foreach (var area in group.ListAreaDTO)
                {
                    html = BuildHtmlTag(area);
                        <script>
                            KriterAlanlariHtml[@sayac] = "@MvcHtmlString.Create(html)";
                        </script>
                    sayac++;
                }
            }
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM