5

Anyone know if it is possible to post a single form with multiple buttons and each button post to a different controller action in Sitecore? On my scenario I have a controller which has 3 actions:

1- load of the page

2- httppost from button A

3- httppost from button B

I'm using an using (Html.BeginForm()) to declare my form and I'm declaring the buttons like this:

<button type="Submit" id="btn" formaction="MyFormActionA"  formmethod="POST" class="btn btn-large">
<button type="Submit" id="btn" formaction="MyFormActionB"  formmethod="POST" class="btn btn-large">

The problem with this approach is that it posts to a different url and doesn't really work. I know that there are ways around that by setting the form action using javascript and things like that. What I'm wondering is whether it is possible to achieve that using this approach or a similar approach where one can post to different actions withing the same form. As far as I understand it is possible to do this with ASP.NET MVC but not sure on Sitecore.

  • 1
    I'm voting to close this question as off-topic because it's an MVC question and doesn't relate to Sitecore at all. – Dylan Young Nov 15 '17 at 20:29
  • 1
    updated question as this there are differences in Sitecore and ASP.NET MVC and this is really about there it's possible to achieve that in Sitecore or not – Diego Nov 15 '17 at 20:36
  • Can you provide more examples of your code, such as the code in your controller? Also I noticed above you have id="btn" for both buttons, could you remove the id attribute, or just change them to be different. – Dylan Young Nov 15 '17 at 21:04
  • 3
    Choose any method here: stackoverflow.com/questions/442704/… – Anton Nov 15 '17 at 21:15
  • I think your issue is that you're posting to an URL that sitecore cannot process due to custom routing. Can you provide the complete razor markup snippet? The bigger question is how you're planning to process the POST. Are you desiring to achieve that via Action Method? My suggestion is to utilize WFFM form instead. It's designed to process input and you can build action events to process the data. – Roman Nov 16 '17 at 2:33
0

Using the approach described on the question doesn't seem to work. The best I found was mentioned by Anton's link which is essentially is have two html buttons with the same name and specify a specific value for each of them. On the post you can capture what the value is for that element and determine what button is triggering the post and add custom logic based on which button is triggering the post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.