2
votes

What is done:

On 1 single Survey page user controls are added dynamically. It's implemented using ASP.NET 4.0, Pressing on "Next", "Previous" buttons user gets another 5-10 controls (which is dynamically built and added to the Survey page - trivial ASP.NET GET/POST), and data entered/selected on previous bunch of controls page is saved to DataBase

What is determined in runtime:

  • the number of user controls
  • type of user controls ( radio button list, check boxes, text box etc. inside user controls)
  • the number of asp.net controls inside user control (number of radio button inside radiobutton list (which in its turn sits in user control), number of check boxes inside user control, etc ) )

Is there way to implement that functionality using MVC 3? (without a big troubles)

Why this implementation is considered, because:

  • It allows do AJAX-replacing of controls on Survey page
  • In nearest future application needs to provide the same functionality for mobile devices, here MVC 4 comes to arena with new functionality for mobile devices.

(all suggestions are welcome)

1

1 Answers

1
votes

I am going to assume you are using the standard view engine, but it is pretty easy to do what you need to.

Just use RenderPartial and supply your control/view name and your view model.

<% RenderPartial("MyControl",theViewModel) %>

You could do something something like this. It assumes you have a collection of data which contains a property that is the name of your control/partial view and a property which contains the data model.

<% for ( int i=0;i<data.Count;i++) { 
     RenderPartial(data[i].ControlTypeName, data[i].Model);
 }%>