I have a question regarding how to properly use partial views that also need their own local js. Let me explain what I mean:
Suppose I have a master page that will include, in some sort of tabbed-panel, n
number of entities. Let's use the common example of "employees". Now, every employee would have a name field, a surname field, and so on. Each field may be editable in some way, or affect another field or object on the page; such as an input box managing a progress bar, but I digress.
A simple way of writing n
amounts of blocks of code, I would see fit to use a repeating partial view for every "employee". However, I also need each partial view to be independent of the rest and have their own local javascript controlling the fields/objects in the view.
I understand that it's bad practice to have javascript in a partial view, so how would I accomplish this otherwise?
To be clear: The javascript needs to be local and contained because, for example, each partial view may need a javascript variable called "name", pointing at each specific view's name. Since there are (or can be) n
views, I cant just make name1
, name2
etc, since I have no idea how many names there will be. It seems, in my mind anyways, that a solution is to somehow render each partial view with js that can handle itself, though this is said to be bad practice. So how would one go about accomplishing a task like this?
I understand this is more of a theory question than an ask of help with code, so please let me know if I've posted this in the wrong place.
Thank you,