0

I have a main .cshtml view that uses jQuery $.Ajax to append returned PartialView result (e.g. return PartialView(partialView, model); ... from my controller action) to a div element on that main view page.

The main view page have inline javascript codes in it.

The partial view page also has some inline javascript codes in it.

The application runs OK. But at run time, I cannot see javascript codes from the partial view page with FireBug. I only see the javascripts of the main view page.

How can I see the javascript of the partial view page with FireBug? Please help.

Thank you.

1 Answer 1

1

you shouldn't put javascript code in a partial view since it gets inserted into the middle of the page. Put the javascript code for the partial into the main page. To fire events on that partial you need to tie them to the document

$(document).on('click', '.Class', function(){
    // do something
});

where .Class is the selector for a field on your partial view. Let me know if you have any questions.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank yo for your reply. The main page can call up to 10 different complex partial view forms based on a context variable. Each complex partial view contains several html elements or tags. Putting all java scripts from 10 partial views in the main view can make that main view too heavy, complex and hard for maintenance ?
then I would use a dedicated script file that you reference from the main page. That way your main page isn't too cluttered and your script is all in one place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.