Reputation: 5907
G'day all.
I'm still new at this MVC thing and am trying to get my head around some design basics.
I have a 'control' (old web forms lingo?) that I want to use on multiple pages. It's a standard log in box, ie, username, password etc with a submit button and code specific to it.
I have created this as a partial view. This renders fine in both of the pages/views where it's used, however my question is where is the best place to put the code that fires when the form (in the partial view) is submitted?
Do I create HTTPPost attributes in both of the 'full' views that then call another class of 'general functions' that has the code specifically related to the partial view? Ideally, I guess that I want a "SharedController" or something that has action methods for things like this, however it all seems that this would get out of hand as the application grows.
I hope that this all made sense. Thanks in advance,
Z
Upvotes: 1
Views: 3911
Reputation: 8562
In general, if you'll want to use a partial view (RenderPartial) when you want to break out some portion of the main view, say you're rendering a complex type which is off the main Model.
For what you want, I think using RenderAction would be the way to go. You'd create a separate Logon controller, and your partial view would be tied to this controller. Basically your logon control is a self contained unit of functionality which the hosting views don't need to have any knowledge about.
RenderAction will do the whole controller lifecycle separately for LogonController, and your form will post back to that controller.
Upvotes: 3