开发者

Adding Jquery functionality on PartialView load

How can I attach jquery on an ASP.NET MVC partial load. I've a form rendered in a partial that has some jquery attache开发者_StackOverflow中文版d, but that code is not running at all


Copy the jquery file into your "scripts directory" and then format the top of your control as follows: (Assuming you use c# ;-)

<%@ Control
    Language="C#"
    Inherits="System.Web.Mvc.ViewUserControl<Your Model>"
%>

<%-- insert your script files name and location here --%>
<% string jqueryLink = "~/Scripts/jquery-1.4.1.min.js" %>

<script
    type="text/javascript"
    src="<%= ResolveUrl(jqueryLink) %>">
</script>

Be happy and enjoy life, Julian


That depends on how you load your partial - MS Ajax or jQuery .ajax(). For example, jQuery (as far as I remember) only evaluates scripts in head tag of the loaded partial (I may be wrong, though).

So you really need to provide your code - how do you load partial and what it does contain.


If your partial view is being loaded via Ajax you will need to use the jQuery "live" method. This method allows you to bind events to DOM elements that will be added to the page via Ajax.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜