In my opinion, in this case, there is no debate about Web forms versus Mvc, but only a misunderstanding of @josequinonesii problem. He is right in this case it make no sense to pu "if"
in the view, but the logics to select meed to be in controllers.
Why?
His application is not like enabling information on the family when the user select he his married, but the main job of the business Layer is JUST SELECTING THE QUESTIONS. To understand better this, please think to the windows help that drives the user to
a solution in case of problems with drivers and/or operating system.
There is no need to break the separation of concerns between View and controller to solve this problem. Controllers decide What questions to show and the Views decide How.
The point that generated the misunderstandig is that all questions are inserted in the same page instead of a sequence of pages. However, also this decision might make sense to allows the user to changes previous choices easily. Anyway, Using various controlles
called by RenderAction, may easily solve the problem and is not very different from having the questions in different pages.
I believe you do have the solution and if you can confirm my understand that would be great and I can mark your answer as the THE ANSWER!
So after some reading about RenderAction about how I could make best use of this it appears that I would have a controller that ultimately called in a from view using a similar syntax:
I think you call Html.RenderAction for each "piece" (or module) of your view. You then create actions for each "piece". This way you can pass the specific arguments to each one so they decide wether they need to be rendered and what data they need to display.
Just remember that this has to be one big form that posts every value back (kinda like web forms).
When I say it like this, then I start to think maybe the original suggestion to have a helper for each seems more appropriate. For me, if the logic is complex and tied to business rules then I probably would use the RenderAction approach.
I'd also use my preference to keep the controller's as thin as possible (skinny controllers) and maybe have an application service that the controller delegates calls to.
In your case I suppose you use a different RenderAction for each group of "dynamic" set of input.
You do something like:
RenderAction("actionName", new {param1=param1Value, param2=param2Value...})
where param1Value and param2Value are values that depends on the answer to other questions. Maybe you have put them in som property of the ViewModel and you refer to them with Model.Answer1.....and so on. If you do this way the action methodd "actionName"
will be called with param1 set to param1Value etc. The HTML generated by the PartialView returned by the controller will be put in the place where you put the RenderAction helper.
are values that depends on the answer to other questions.
To be clear there is no dependency on previously answered questions.
The controller would obtain the HTTPGET values where one of the name/value pairs will be the ID that will be used to know which "question set" to return from the model.
sachingusain
Star
8786 Points
1702 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 05, 2011 10:09 PM|LINK
This is unrelated but an interesting post from Scott Gu:
About Technical Debates (and ASP.NET Web Forms and ASP.NET MVC debates in particular)
Thanks.
francesco ab...
All-Star
20944 Points
3286 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 06, 2011 10:46 AM|LINK
In my opinion, in this case, there is no debate about Web forms versus Mvc, but only a misunderstanding of @josequinonesii problem. He is right in this case it make no sense to pu "if" in the view, but the logics to select meed to be in controllers.
Why?
His application is not like enabling information on the family when the user select he his married, but the main job of the business Layer is JUST SELECTING THE QUESTIONS. To understand better this, please think to the windows help that drives the user to a solution in case of problems with drivers and/or operating system.
There is no need to break the separation of concerns between View and controller to solve this problem. Controllers decide What questions to show and the Views decide How.
The point that generated the misunderstandig is that all questions are inserted in the same page instead of a sequence of pages. However, also this decision might make sense to allows the user to changes previous choices easily. Anyway, Using various controlles called by RenderAction, may easily solve the problem and is not very different from having the questions in different pages.
Mvc Controls Toolkit | Data Moving Plug-in Videos
josequinones...
Member
1 Points
13 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 07, 2011 09:34 PM|LINK
I've updated my question to clarify my goal.
For brevity sake my examples will be extremely small.
Questions Set 1
Question 1, 5 possible answers, radio group
Question 2, open ended, textarea
Question 3, state list, dropdownlist
Questions Set 2
Question 1, 7 options, check boxes
Question 2, true/false, radio group
Question 3, date, date picker
Questions Set 3
Question 1, one word answer, textbox
Question 2, one word answer, textbox
Question 3, one word answer, textbox
How would I get the MVC2 form controls on a "dumb view"?
josequinones...
Member
1 Points
13 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 08, 2011 04:21 AM|LINK
@francesco
I believe you do have the solution and if you can confirm my understand that would be great and I can mark your answer as the THE ANSWER!
So after some reading about RenderAction about how I could make best use of this it appears that I would have a controller that ultimately called in a from view using a similar syntax:
Nick_Uk
Participant
800 Points
445 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 08, 2011 12:40 PM|LINK
I think you call Html.RenderAction for each "piece" (or module) of your view. You then create actions for each "piece". This way you can pass the specific arguments to each one so they decide wether they need to be rendered and what data they need to display.
Just remember that this has to be one big form that posts every value back (kinda like web forms).
When I say it like this, then I start to think maybe the original suggestion to have a helper for each seems more appropriate. For me, if the logic is complex and tied to business rules then I probably would use the RenderAction approach.
I'd also use my preference to keep the controller's as thin as possible (skinny controllers) and maybe have an application service that the controller delegates calls to.
Site
Blog
Nick_Uk
Participant
800 Points
445 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 08, 2011 12:42 PM|LINK
Just remember that Html.RenderAction renders a parital view and that essentially is your "control".
Site
Blog
francesco ab...
All-Star
20944 Points
3286 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 08, 2011 05:15 PM|LINK
See here: http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx
for examples of use of RenderAction and Action.
In your case I suppose you use a different RenderAction for each group of "dynamic" set of input.
You do something like:
RenderAction("actionName", new {param1=param1Value, param2=param2Value...})
where param1Value and param2Value are values that depends on the answer to other questions. Maybe you have put them in som property of the ViewModel and you refer to them with Model.Answer1.....and so on. If you do this way the action methodd "actionName" will be called with param1 set to param1Value etc. The HTML generated by the PartialView returned by the controller will be put in the place where you put the RenderAction helper.
Mvc Controls Toolkit | Data Moving Plug-in Videos
josequinones...
Member
1 Points
13 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 08, 2011 05:39 PM|LINK
To be clear there is no dependency on previously answered questions.
The controller would obtain the HTTPGET values where one of the name/value pairs will be the ID that will be used to know which "question set" to return from the model.
I hope that clarifies things a little.
josequinones...
Member
1 Points
13 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 08, 2011 05:44 PM|LINK
This is why I think the render action is probably the "cleanest" and most resuable approach as one does not want to create 20 views to maintain.
josequinones...
Member
1 Points
13 Posts
Re: Dynamic Form - Is mvchtmlstring the answer?
Jan 08, 2011 05:44 PM|LINK
This is why I think the render action is probably the "cleanest" and most resusable approach as one does not want to create 20 views to maintain.