Is it OK to put JavaScript in Partial Views

前端 未结 5 1306
死守一世寂寞
死守一世寂寞 2020-11-29 02:03

I’m working on the web app where the main page contains two parts: the constant block which is always visible and the info-block made up by one of 3 partial views. Each of t

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 02:19

    I do this and find it highly convenient. It works well to dynamically load partial javascript snippets with the availability of ViewBag, HttpContext, etc.

    It results in something that feels like using T4 templates.

    You can even get javascript validation, intellisense, etc if you add phantom script tags like this.

    @using System.Configuration
    @if (false)
    {
        @:
    }
    

提交回复
热议问题