tags:

views:

309

answers:

4

I have a master page which all my views inherit from. The issue I am having is with the form tag which is created in the master page and then the form tag which is created in view.

Because of the form being inside the master page form, all my postbacks are sent to the controllers Index method and its forcing me to create a new method Index which forces an HttpPost.

Further this is causing problems with routes like: /projects/add/ and /projects/delete/1 where everything is router to the Index Method.

WTF? Am i missing something here?

Thanks anyone

+1  A: 

Remove the form from the master page.

Check some sample videos here to better understand the MVC philosophy.

BTW: In ASP.NET MVC, there is no postback.

gius
There is nothing in MVC that prevents a postback to the same action that created the view, it is however not necessary recommended.
MrJavaGuy
+1  A: 

In my opinion you really ought to think of MasterPages as layouts and not as functional pages. In fact views do not "inherit" from master pages at all. In traditional Webforms, masterpages are in fact user controls. So I would try to not put base-class functionality into a masterpage. So perhaps that is where some of the confusion comes in.

Trevor de Koekkoek
the master page has no functionality. Out of the box it has a form element. So my containers that feed data into the master are themselves forms so now you have a serverside form inside another form. I've commented them out individually and still the same issue.
NTulip
The MVC version of master pages does NOT have a form element out of the box. Perhaps you chose the Webforms version. You have to be careful when you select a masterpage from the templates in Visual Studio. It's easy to select the wrong one.
Trevor de Koekkoek
A: 

ASP.NET MVC isn't supposed to do "PostBacks"... that's completely missing the point. Remove any "largely-encompasing-form-tags" you have out there, and only put a "form" tag around input fields that are meant (for a specific purpose) to POST to some sort of action.

The fact that you have an all-encompasing form tag (as is true with traditional asp.net) means that you don't have a defined reason for that form, and that is (again) missing the point of MVC.

This is an older article, but it can help with the differences between traditional, and MVC: ASP.NET MVC in the Real World

Timothy Khouri
A: 

If you need common form elements on every page, hence the reason you have a form on your master page, then move the form elements to a user control located in the shared folder along with your site.master file. Then include the user control via Html.RenderPartial in each of your view pages. That will only require 1 line of code and maybe a div tag per view which isnt to bad.

BTW is the form located in the master page a login or search control by chance?

Todd Smith
the form i care about is inside the view which has a master page. It is not a login or a search control.
NTulip