I am having trouble deciding whether it is ok to construct HTML in controller actions and provide this HTML back to AJAX calls from my view (using jquery).
For instance, when selecting a client via jQuery Autocomplete, besides just getting the selected client ID we also need to construct a display or edit form for it. We might:
- Have like dozens of placeholder
div
s with proper IDs and receiveClient
JSON object from out controller action and then update those divs with the content from our object (very error prone, lots of IFs in our JS code, etc.), - or instead of requesting for a
Client
JSON object rather request the prepared HTML and just insert it into the view (more appealing solution, logic is moved into controller and easiear to maintain - I rather maintain C# code than JS).
Do you think these are valid options? What do most modern apps do?
- While 2. will work perfectly for client's display form will it work for edit for?. Eedit form should contain HTML
input
controls because I want client properties to be POSTed back because when they are posted back to the controller I can materialize a viewmodel with them.