views:

46

answers:

2

I have a one form tag inside my Index.aspx view. Index.aspx contains several partial views and using the same model to render them.

Now when any partial view is posting the form with submit button form is posted to OneActionMethod. But I want for some partial views to post form to OtherActionMethod.

How can I achieve this, without using action links, just with submit button in this particular patial view?

I`ve wrote the update in comments to this question. Answer is still not clear to me.

+1  A: 

You sound like you are trying to program "WebForms" style in MVC.

Why do you have one big form enclosing all of your partials? Separate them into unique forms, and have each one post to it's appropriate action.

EDIT: With your further clarification, the only thing I can think of (aside from redesigning to use individual forms, which does lead to problems if they want to share data), is to post to a single action, and then route the request to a private member within the controller for ActionA or ActionB depending on a particular form element.

FlySwat
It`s not one big form, it`s rather small form, editing small pieces :-). So it`s ok, and even if it`s not can`t change it, it`s the way I was asked to do this. So the question still there :-)
Yaroslav Yakovlev
The answer is to move each individual piece into their own form. A form should simply be a logical grouping of data to post to a action. Any more is an abuse. You need to rethink your strategy to work MVC style.
FlySwat
Thanks for your answers. Please, read my update, I`m very interested in your opinion on how to do this.
Yaroslav Yakovlev
+1  A: 

i believe a little javascript will get ur job done. u have to hook the submit event of the form and change the action attribute of the form. remember action is attribute of form not of a submit button. in jquery u can do something like

$("#myform").submit(function(){
   if(isFirstSubmitButton){
    $(this).attr(FirstAction);
   }
   else if(isSecondSubmitButton)
   {
    $(this).attr(SecondAction);
   }
return true;
});
Muhammad Adeel Zahid
Assuming he is ok with his application being totally broken without Javascript.
FlySwat
Agree with FlySwat, it seems like a hack.
Yaroslav Yakovlev
Just marked this as answer as it better fits for question. Sure I still think it`s a hack and if we are going to make things in a proper way we should use one form per partial view. So I upvoted FlySwat answer :-)
Yaroslav Yakovlev