I just started playing with MVC for the first time and I find it extremely intriguing. Clearly, my brain is now hard-wired to think in terms of forms and events.
Here's Question 1:
If I have a form that goes through multiple "sections", do I actually create multiple views? When I look at views in MVC 2, they look more like User Controls in Web Forms i.e. no body tag, nothing.
I assume I would then put the logic in a controller to call those views in the right order. Is this right?
Question 2:
If I wanted to implement a modal window, how would I handle that? Would what I display in the modal window be in a separate view?
1. Depend what are you thinking of "sections" . If they are GUI for objects that repeats over the project, yes, it is better to create an user control and display with Html.RenderPartial
Thanks for your response. By sections, I mean this:
Scenario 1:
Form with so many questions that it just makes it better to break it down into sections. I handled such scenarios using MultiView control in the Web Forms world. So the question is then do I create multiple MVC views that get called by the controller?
Scenario 2:
In simple forms, I also used MultiView control to display my final message i.e. "Thank you for your submission" or "Error. Call your system admin". I'd put the form in the first view of a MultiView control and put a label or literal control in the second view.
At the end of my process, I'd simply display the second view of my MultiView control.
So if I understand you correctly, I'd be creating MVC views for these purposes that get used over and over again by different functions in my application. For example, it would actually make sense for me to create one MVC view that I always call as the final
step of each user interaction form that displays those "Thank you" or "Error" messages. This would actually reduce the amount of code I generate because I've just created a reusable view.
Am I on the right track as far as MVC way of doing things?
note "The value of TempData persists only from one request to the next."
multiple submit buttons: (without JavaScript)
on your .aspx page, add a second button:
<input type="submit" value="Previous"
name="submitButton"/>
<input type="submit"
value="Next" name="submitButton"/>
in your Controller:
// POST: /Home/Edit/5
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Edit(Movie movieToEdit,
string
submitButton)
{
if (submitButton == "Previous")
et cetera
Regards,
Gerry (Lowry)
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Thanks for your response. The main thing that I'm trying to accomplish here is to understand the way an "experienced" MVC programmer would approach this scenario.
Another idea comes to mind is to have a single form with multiple DIVs in it that I can hide and display using JavaScript. A good example would be employee registration for an HR application. There are so many facets of an individual that it makes sense
to have sections in a form i.e. Personal Information , Education, Previous Employment, Emergency Contacts, etc.
If you were given the task of creating this form, how would you approach it from an MVC programming model stand point?
P.S. I do appreciate the fact that even in this scenario, TIMTOWTDI For instance if I have separate types of data that
will go into different tables in the database, I may want to use separate MVC views and collect the data and dump it into the database. However, I'm just giving you one simple scenario and would love to see how you'd approach it based on your MVC experience.
Thanks again for entertaining my newbie questions.
Sam, this is a quick response because I'm under time pressure
and unable to provide a more thoughtful response at this instance.
Quick thought: because ASP.NET MVC as a paradigm
separates Views from Models via the inbetween Controllers,
you could create a MVC application quickly just to get your
ideas expressed in code and then refactor the parts you
dislike later. With ASP.NET MVC you are less locked in
than say with WebForms. The "separation of concerns"
that ASP.NET MVC allows you to express yourself also
facilitates both TDD and the subsequent refactoring of your
Models, Views, and Controllers.
How you initially implement your application
is a matter of personal preference (and/or
direction from your management) and what
will work best for your end users. For example,
stackoverflow.com has a unique UI that works
because its user base is mainly other developers;
imo, a user with low computer literacy would fell
lost in the wildnerness at SO.
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
SamU
Contributor
2895 Points
1627 Posts
Two Annoying Newbie Questions about MVC style of programming
Feb 11, 2010 08:01 PM|LINK
Hi,
I just started playing with MVC for the first time and I find it extremely intriguing. Clearly, my brain is now hard-wired to think in terms of forms and events.
Here's Question 1:
If I have a form that goes through multiple "sections", do I actually create multiple views? When I look at views in MVC 2, they look more like User Controls in Web Forms i.e. no body tag, nothing.
I assume I would then put the logic in a controller to call those views in the right order. Is this right?
Question 2:
If I wanted to implement a modal window, how would I handle that? Would what I display in the modal window be in a separate view?
Sam
ignatandrei
All-Star
135081 Points
21666 Posts
Moderator
MVP
Re: Two Annoying Newbie Questions about MVC style of programming
Feb 12, 2010 09:05 AM|LINK
1. Depend what are you thinking of "sections" . If they are GUI for objects that repeats over the project, yes, it is better to create an user control and display with Html.RenderPartial
2.Search for jquery modal
http://www.ericmmartin.com/projects/simplemodal/
And yes, it must be another view - or a div inside your form
SamU
Contributor
2895 Points
1627 Posts
Re: Two Annoying Newbie Questions about MVC style of programming
Feb 12, 2010 03:49 PM|LINK
Thanks for your response. By sections, I mean this:
Scenario 1:
Form with so many questions that it just makes it better to break it down into sections. I handled such scenarios using MultiView control in the Web Forms world. So the question is then do I create multiple MVC views that get called by the controller?
Scenario 2:
In simple forms, I also used MultiView control to display my final message i.e. "Thank you for your submission" or "Error. Call your system admin". I'd put the form in the first view of a MultiView control and put a label or literal control in the second view. At the end of my process, I'd simply display the second view of my MultiView control.
So if I understand you correctly, I'd be creating MVC views for these purposes that get used over and over again by different functions in my application. For example, it would actually make sense for me to create one MVC view that I always call as the final step of each user interaction form that displays those "Thank you" or "Error" messages. This would actually reduce the amount of code I generate because I've just created a reusable view.
Am I on the right track as far as MVC way of doing things?
Sam
gerrylowry
All-Star
20515 Points
5713 Posts
Re: Two Annoying Newbie Questions about MVC style of programming
Feb 12, 2010 04:02 PM|LINK
TIMTOWTDI =. there is more than one way to do it
One approach would be wizard like View pages ...
you'd move from page to page pulling the data
you require to the next page using TempData.
You can have multiple submit buttons for a single "form";
you could use one button for forward, another for back.
using TempData:
http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.tempdata.aspx.
http://msdn.microsoft.com/en-us/library/dd394711.aspx:
"Passing Data in an ASP.NET MVC Application"
note "The value of TempData persists only from one request to the next."
multiple submit buttons: (without JavaScript)
on your .aspx page, add a second button:
<input type="submit" value="Previous" name="submitButton"/>
<input type="submit" value="Next" name="submitButton"/>
in your Controller:
// POST: /Home/Edit/5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Movie movieToEdit, string submitButton)
{
if (submitButton == "Previous") et cetera
Regards,
Gerry (Lowry)
SamU
Contributor
2895 Points
1627 Posts
Re: Two Annoying Newbie Questions about MVC style of programming
Feb 12, 2010 04:15 PM|LINK
Gerry,
Thanks for your response. The main thing that I'm trying to accomplish here is to understand the way an "experienced" MVC programmer would approach this scenario.
Another idea comes to mind is to have a single form with multiple DIVs in it that I can hide and display using JavaScript. A good example would be employee registration for an HR application. There are so many facets of an individual that it makes sense to have sections in a form i.e. Personal Information , Education, Previous Employment, Emergency Contacts, etc.
If you were given the task of creating this form, how would you approach it from an MVC programming model stand point?
P.S. I do appreciate the fact that even in this scenario, TIMTOWTDI
For instance if I have separate types of data that
will go into different tables in the database, I may want to use separate MVC views and collect the data and dump it into the database. However, I'm just giving you one simple scenario and would love to see how you'd approach it based on your MVC experience.
Thanks again for entertaining my newbie questions.
Sam
gerrylowry
All-Star
20515 Points
5713 Posts
Re: Two Annoying Newbie Questions about MVC style of programming
Feb 12, 2010 04:46 PM|LINK
Sam, this is a quick response because I'm under time pressure
and unable to provide a more thoughtful response at this instance.
Quick thought: because ASP.NET MVC as a paradigm
separates Views from Models via the inbetween Controllers,
you could create a MVC application quickly just to get your
ideas expressed in code and then refactor the parts you
dislike later. With ASP.NET MVC you are less locked in
than say with WebForms. The "separation of concerns"
that ASP.NET MVC allows you to express yourself also
facilitates both TDD and the subsequent refactoring of your
Models, Views, and Controllers.
How you initially implement your application
is a matter of personal preference (and/or
direction from your management) and what
will work best for your end users. For example,
stackoverflow.com has a unique UI that works
because its user base is mainly other developers;
imo, a user with low computer literacy would fell
lost in the wildnerness at SO.
g.