开发者

Why can't I reference JavaScript files in my View?

My JS works when I reference it in the Ma开发者_运维百科sterPage, and it works when I reference it in a Partial View (.ascx), but not when I reference from the View (.aspx).

Any ideas why?


Is the path to the script file correct in your View?

If you inspect HTTP traffic with something like Fiddler or Firebug's Net tab, do you see your script resources being downloaded to the browser?

You might want to use UrlHelper.Content and the relative path to render the script source in the page or perhaps create a HtmlHelper extension method to render out a script tag for you (I think one exists in MVCContrib if you're using that already).


So if you have a block declared in an included file (let's just pretend it looks like)

function alertMe(someValue) {
  alert(somevalue);
}

and in your master page, aspx, and ascx you have

<script type="text/javascript">
  alertMe("some string");
</script>

and it works in the master page and the ascx but not the aspx?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜