Is it OK to put JavaScript in Partial Views

前端 未结 5 1294
死守一世寂寞
死守一世寂寞 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:12

    I agree with Wahid that you shouldn't put JavaScript in views at all partial or otherwise. I've seen enough code that does this to know it only leads to no good.

    I would also say that you should be able to transfer the logic encapsulated in the Razor syntax into the JavaScript, you just need to pass to your JavaScript the information needed by your logic.

    I'm just guessing from experience with this next comment but you should design the JavaScript the same way you would design the structure of your C# or VB.NET code. That way the logic that you are using Razor for should be part of your JavaScript.

    That way your JavaScript will be easier to maintain and I assume Resharper should also be happier.

提交回复
热议问题