Jquery or javascript issue in my partial view

Can jQuery or JavaScript code be used in partial views?

I have a grid in my partial view, and I'm trying to hide a single grid element using jQuery in this partial view. I can not do it. But the same code works if I use it without a partial presentation.

Can anybody help me?

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 cannot pop up a warning in this window.

thanks

+7
source share
3 answers

There may be several reasons why this does not work.

To make sure your jQuery is partially viewable, you can try adding jquery links on your partial view page. Hoping you don't have a similar problem like http://forums.asp.net/t/1649526.aspx/1

Secondly, if you call it through AJAX, javascript included in this partial view does not start MVC AJAX. Follow this guide to make it work for you.

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

+11
source

Check the output page for nested tags or if any markup fails. Also, check for errors in the browser javascript console.

+2
source

It may be a conflict, or the $ character is not interpreted correctly, try to do:

 <script type="text/javascript"> jQuery(document).ready(function(){ alert("DOM loaded!"); }); alert("this script tag is executing properly!"); </script> 
+2
source

All Articles