Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  6] [ 5]  / answers: 1 / hits: 18273  / 13 Years ago, wed, may 4, 2011, 12:00:00

Can I use jQuery or JavaScript code in partial views?



I have a grid in my partial view and I am trying to hide one grid element using jQuery in that partial view. I am not able to do so. But same code works if I use it without a partial view.



Can anybody help me out?



Here is my code



<%@ Page Title= Language=C# Inherits=System.Web.Mvc.ViewPage<NascoBenefitBuilder.ViewModels.Obn.ProductTemplate.ObnProductTemplateMainData> %>
<script type = text/javascript language=javascript>
$(document).ready(function(){
alert(success);
});
</script>


This code is in my partil view but when this page loads I am not able to popup this alert box.



thanks Thanks


More From » c#

 Answers
38

There could be few reasons for this not working.



Just to make sure your JQuery is available to partial view, you can try adding jquery references in your partial view page. Hoping you don't have similar issue like this one http://forums.asp.net/t/1649526.aspx/1



Second, if you are calling it through AJAX, javascript included in that partial view is not run by MVC AJAX. Follow this guideline to have it work for you.



http://geekswithblogs.net/DougLampe/archive/2010/11/12/execute-javascript-in-mvc-partial-view.aspx


[#92403] Tuesday, May 3, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myakylas

Total Points: 66
Total Questions: 85
Total Answers: 95

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
myakylas questions
Thu, Apr 28, 22, 00:00, 2 Years ago
Thu, Apr 8, 21, 00:00, 3 Years ago
Sat, Sep 19, 20, 00:00, 4 Years ago
;