razor - jQuery unrecognized in a view that is generated using @Html.Raw -


i have razor view has jquery included , javascript function on view recognizes jquery. have multiple div elements contain other view html within view using

@foreach(record record in records) {     <div>@html.raw(record.recordhtml)</div> } 

if include javascript function inside of foreach div, fails recognize jquery.

    @foreach(record record in records)     {         <div>@html.raw(record.recordhtml)</div>         <script>                         function getelement()             {                 $("#recordid");             }         </script>     } 

the work around include jquery in each iteration, don't understand why needed if jquery included on primary view.

can explain why each div needs own jquery include?

there misunderstaning. there definately not need jquery include in every iteration. prove it, change code to

 <script src="path/to/jquery.js" type="text/javascript"></script>  @foreach(record record in records)     {         <div>@html.raw(record.recordhtml)</div>         <script>                         function getelement()             {                 $("#recordid");             }         </script>     } 

notice, jquery explicitly included before loop.

the real problem here jquery not loaded before scripts inserted. yes, jquery may loaded.

but, need review order of loading , use of master , partial layouts ensure jquery loaded before.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -