Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 12, 2010 04:46 PM by gerrylowry
Feb 11, 2010 08:01 PM|LINK
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?
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?
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
And yes, it must be another view - or a div inside your form
Feb 12, 2010 03:49 PM|LINK
Thanks for your response. By sections, I mean this:
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?
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?
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.
"Passing Data in an ASP.NET MVC Application"
note "The value of TempData persists only from one request to the next."
on your .aspx page, add a second button:
<input type="submit" value="Previous"
in your Controller:
// POST: /Home/Edit/5
ActionResult Edit(Movie movieToEdit,
if (submitButton == "Previous")
Feb 12, 2010 04:15 PM|LINK
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.
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.
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.