I am loading one of several partialviews depending on a selection that’s made. Inside those partial views I need to capture all of the form elements that are included on that partialview inside a jquery array.
currently I’m using this:
var allInputs = $('input[data-var]').add('select[data-var]').add('textarea[data-var]');
but that also captures all of the form elements from the parent view. Is there a way to narrow the scope to only grab the elements on “this” partial view?
Is your partial view rendered within a specific element? If not, you could modify the partial view to wrap all elements and then scope your jQuery selector to that element:
Partial View:
Then, your javascript would be as follows:
Take a look at the jQuery docs for more on selector context: http://api.jquery.com/jQuery/#jQuery1