开发者

Pointing src attribute of script tag to download js from an action method in asp.net mvc 2.

I have the following SCRIPT t开发者_运维百科ag in one of the ViewPage in MVC 2 :-

<script type="text/javascript" src="Account/Handler?ms=connect"></script>

But, it does not download the script from that action method. I had setup a breakpoint in the Handler action of Account controller, but it does not hit. The action method is not called.

If I use this same tag in HomeController and point to Home/Handler then it downloads and action method is called.

Please help.


Are you sure it is the correct URL? If you are already at "http://mysite/Account" for instance, that will point to "http://mysite/Account/Account/Handler?ms=connect". You should use Url.Action():

<script type="text/javascript"
    src="<%= Url.Action("Handler", "Account", new { ms = "connect") %>"></script>

If you use google chrome for your browser, you can view source and click on the url to see what is returned. Of course you need to set the content type to "text/javascript" but if it works in your home controller I assume you already to that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜