简体   繁体   English

这是使ASP.NET MVC和javascript intellisense发挥出色的“正确”解决方案吗?

[英]Is this the “correct” solution for getting ASP.NET MVC and javascript intellisense to play nice?

Due to how paths relate to VS resolving the path to a JS file and then how the actual path at runtime is resolved via the browser, I've currently got the following placed at the top of my Master Page within my application so that all my views have the appropriate JS intellisense and resolve correctly for execution: 由于路径与VS的关系如何解析到JS文件的路径,以及如何通过浏览器解析运行时的实际路径,因此,我目前在应用程序的“母版页”顶部放置了以下内容,视图具有适当的JS intellisense并正确解析以执行:

<% if (false) { %>
    <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<% } else { %>
    <script src="<%= ResolveUrl("~/Scripts/jquery-1.3.2.js")%>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/MicrosoftAjax.debug.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/MicrosoftMvcAjax.debug.js") %>" type="text/javascript"></script>
<% } %>

Is this may how others are doing it or is there some crazy better way that's going to make me look like an ass? 这可能是其他人的做法吗,还是有些疯狂的更好方法会让我看起来像个屁股? Thanks! 谢谢!

如果对Scott Guthrie足够好 ,那么我会认为这是正确的方法(目前,他们可以始终在VS 2010中解决此问题!)。

Yes, I agree that's the correct solution. 是的,我同意这是正确的解决方案。 Just throwing it into the master page won't be enough though - you also need to put it into all the partial view files you may have. 但是,仅将其放入母版页中是不够的-您还需要将其放入可能具有的所有部分视图文件中。 I just blogged about this yesterday with rather extensive comments on the background. 我昨天刚刚在博客上发表了有关此背景的大量评论。

If you have many script files, it might be a good idea to group all these into one .js file and keep including that, so in case of another script being added you don't have to go around pasting it everywhere. 如果您有许多脚本文件,最好将所有这些文件分组为一个.js文件并继续包含该文件。因此,如果添加了另一个脚本,则不必四处粘贴。 Of course, if you don't use partial (ascx) views, none of this is an issue. 当然,如果您不使用部分(ascx)视图,那么这都不是问题。 But if you need this, take a look at the Intellisense FAQ question 3. 但是,如果需要此功能,请查看Intellisense FAQ问题3。

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

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