I need to transfer some data from my controller in my opinion. This data will be used by jQuery to perform some actions. Data is a short string. I can put it in a hidden text box and access this text box value using jQuery. I could also put the data attribute in the html element that concerns the data. I wonder what would be the best way.
To name a specific case when I had to make this choice: I had a general partial view that needed to make an ajax call to update some data in the view. However, the purpose of the ajax call depends on the context of the partial view. Therefore, I am passing a link to a partial view model. Where can I store this data for jQuery to access it?
I feel that the data attribute is somehow nicer, because I feel that the purpose of the hidden input fields is more about sending the information back along with the rest of the form.
Is there any general opinion about this?
Thanks in advance.
source share