tonyapolis
tonyapolis

Reputation: 201

Dynamically populate ASP.NET MVC 3 Editor Templates based on selection in a dropdown

I am using ASP.NET MVC 3 and am attempting to populate a list of editor templates dynamically based on the selection made in a dropdown. I have no code to post because I am not sure what is the best way to achieve my purpose. My question is not how to use editor templates, but how to use editor templates when the list of related objects changes based on a user selection of the "parent".

Background:

Employees need to complete training checklists for operations they are trained on. The employee will select a checklist template from a dropdown menu, and then checklist items will populate based on the selected checklist template. (Each template has a different set of related items.) Each checklist item is associated with a blank response that the user must mark was completed. The checklist item is for display only; the response is what is being edited.

I know I can populate the checklist items via AJAX & Json, but is there a way to do this using editor templates--with the result of checklist items dynamically displaying based on the checklist template selected? One solution is to use one page to select the template, and then another page to display the checklist items; I would like to avoid this and keep everything on one page if possible. The goal is to populate the checklist items (and blank responses) based on the checklist template selected.

Caveat: Each checklist will have a predefined number of blank responses based on what items are related to the checklist template, so the list size will not change during the completion of the form.

Model:

[ChecklistTemplate] 1------------* [ChecklistItem]

[ChecklistTemplate] 1------------* [Checklist]

[Checklist] 1------------* [ChecklistResponse]

[ChecklistResponse] *------------1 [ChecklistItem]

Any and all help is appreciated. Thank you.

Upvotes: 2

Views: 848

Answers (1)

Aleksei Anufriev
Aleksei Anufriev

Reputation: 3236

For those type of tasks Id suggest to look into: http://knockoutjs.com/ On client side you have tho options:
1. Postback to server (Stinky stuff IMHO).
2. Do some clientside JS.

Id prefer Knockout for clean MVVM approach with events on model change. Made some very complex editors with it and works like a charm so far.

Upvotes: 1

Related Questions