Bundle javascript in partial view to use as widget

Jyozeal
Jyozeal used Ask the Experts™
on
Hi All,

I would like to create a small widget where it contains a search box a submit button and 3 labels and 3 texboxes for displaying employee name , email, phone number. So whenever employee id is entered and upon clicking submit button I would like to make an ajax call to my controller and get the details and fill the partial view. I do not want the ajax call in main view because that will not enable me to use it in other views.

How do I achieve this? Thanks for your time.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008

Commented:
I am not sure what you are looking for, but you should be able to add the script reference in the parent view, and call the function in the partial view.

Author

Commented:
Thanks for your comment. In that case I will not be able to use it as unit. My intention is to use it in various views of my project by just inserting this partial view along the with script. I do not want each view to duplicate the code to load employee details in partial view.
Most Valuable Expert 2012
Top Expert 2008
Commented:
I don't believe that you can add a script reference to a partial view, but there might be some other approaches that I don't know about yet.

Take a look here:

Managing Scripts for Razor Partial Views and Templates in ASP.NET MVC
http://forloop.co.uk/blog/managing-scripts-for-razor-partial-views-and-templates-in-asp.net-mvc#sthash.koeye0dE.dpbs
Sr.Software Engineer
Top Expert 2013
Commented:
I am not an expert with MVC but i think you can get a good reference on the below links
Adding to script bundle from partial view in .NET MVC 5
Adding to script bundle from partial view in .NET MVC 5
hope this helps.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial