Ok, the question title doesn't really reflect the question that well. But here it is in all it's glory.
I am currently making the transition from WebFroms to MVC as everyone seems to want it without really knowing why. Office politics aside.
Am I right in perceiving that a partial view is "like" a webform control in that it is an almost self-contained unit that adds to the overall _layout? IF not - could you please tell me the point and rationale of Partial views - where to use them, when and why?
Sorry not the best explanation - but it is kind of confusing for me, so it's not suprising that my question is confused as well :P
Thanks in advance.
In the web forms philosophy controls are hold UI part and some backend logic, so you can create a combobox control which always display the list items from some DB table with special stile for e.g. always in red rectangle with blue background
In the MVC philosophy partial views just an a view part, so according to the example above particular view will hold only UI component, the rest of the logic (data provider) should be in the controler's action.
MVC decouple UI from data providers, so you can create other view which still can work with previous defined data provider (action) and vice versa you can use the same partial view (view) for other data providers (actions) which have some interface
In a typical win form, you have a form that contains a few custom controls, each custom control implements part of a whole business logic, when the custom control wants to talk to each other, they will pass data across via presenter. Also, each custom control is a combination of windows standard controls(button, label, textbox,etc). In such case, you can think that each standard control is a html element, custom control is partial view, the whole form is a view and presenter is action method + ajax call.
MVC and WebForms are both programming models.
Comparing partial views to Webforms is not comparing apple to apple.
You have to think different when it comes to MVC or even forget about the WebForms
The closest thing to a partial view in webforms would be master pages in my opinion. And that is just the aspx markup aspect (View) of it.
Related
I am building an ASP .NET MVC 3 application, and I want to make sure that I am following the MVC guidelines as well as possible.
I have a front page that displays a list of computer games. Now, it has the same way of displaying the items as another page. How would I do this through an MVC perspective?
Would I have a function in my controller that returns a string containing the HTML of the list of games, and then print that out on both pages? Or how would I do this in a proper way?
partial views. you should be able to find a lot of information about them via search.
Designing a presentation type application which consists of 2 forms, the first form will be used to control the presentation so it can be manipulated on the fly, it will be based off the first monitor of the pc, the second form will be on the second monitor (or projector). I need to update the second form with numbers and pictures during the presentation. In terms of accessing information between forms, would MVC be the best way to do this?
http://www.c-sharpcorner.com/UploadFile/rmcochran/MVC_intro12122005162329PM/MVC_intro.aspx
Cheers!
You don't make it 100% clear if you're are using Forms or WPF (you've put both tags) if you are using WPF the most popular and comfortable design pattern for is generally the Model-View-ViewModel (MVVM) pattern. Is this is quite close to MVC but slightly different. You can read about it here
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
In your application it would mean having data classes that described and manipulated the presentation itself (the model).
Then you would have a view model class (or group of classes) that describe what's visible in each window and the current state of the controls and the currently displayed slide etc. both sets of view models bind to and update the same underlying presentation model.
Finally the XAML and controls render two a 'views' one for each window, the views then become nice and clean binding only to the current state of the ViewModel.
Hope this general outline provides helpful inspiration, if you want and more specific info or advice please ask.
Mark
Using which of these is the best approach while planning Silverlight application? UserControls or Page.
My understanding is that when you have to encapsulate some of the logic of some component, which is truly generic and reusable then use usercontrol else use Page because Page is tightly integrated with browser's history etc, so you can move back and forth and can make use of NavigationService to navigate across pages because if you keep using usercontrols, it is very tiresome to navigate all the way to the required page. Thus we cannot bookmark it because it serves no purpose. We will have to again find our way through the menus in application to reach our desired location.
Is my understanding correct?
Your understanding is correct. Use Pages to integrate with the Navigation framework and the main pages and controls for custom components etc.
I 'am building a small windows form application.
I have a View - a simple form that has some functionality in it.
a Controller - a class that will react to loading, saving, getting data from the model and prepare it form the view etc.
a Model - a class that will get and save data to DB or file.
The controller is creating a form instance an run it, and creating a model instance when needed.
I wonder about how to react in the controller to the view events.
Should I register to the view events (buttons click, combo change etc.) ?
This will make the form controls visible outside the form?
Maybe I have a mistake in the design?
Microsoft has created a framework for Win Forms MVC applications, the Composite UI Application framework.
http://www.codeplex.com/smartclient
It is probably overkill for a small project, but you could look at it and get some ideas.
Can you take a look at this SO post
using MVC MVP patterns in winforms
If you google MVP (Model-View-Presenter) you'll find info on how to implement a seperation of concerns pattern in a Windows form application.
I'm writing a WinForms application and want to have an "MVC-Type" Design. Actually it's more MVP or MVVM,.
The plan is to have a Central Controller which does all the actual work, so that the Forms just render out ViewModels and handle user input, but everything that actually does something goes through the Controller.
I just wonder if this is a good idea, and where to put the Controller? The current idea is to have a static class which is initialized in Program.cs (Sending in some Dependencies like IMyDatabaseRepository) so that it just stays a controller that delegates work between User Interface and Model.
As you might guess, I come from a Web Background and have little experience with WinForms architecture. Previously, my MainForm was the Controller class, holding all the State Variables, which obviously means that my MainForm is my application rather than just a part of the User Interface.
Nice question Michael!
Here are some links:
Sacha Barber's WPF MVVM VS Project Template
Sacha's Article Series on CodeProject.com
Nice article on this Wordpress blog
Hope these help you to structure your project properly!
I don't know if this is a better way, but I am having Structuremap create my controller and database instance.
The main form has no real code in it - it just loads the first set of controls and then starts the controller. The user controls on the form use StructureMap to access the controller.
My project is regular WinForms and not WPF and is my first time using the MVC pattern with WinForms.
You might have a look at the WAF Windows Forms Adapter download. It comes with the BookLibrary sample application which uses a Controller / MVVM design together with Windows Forms.