Is it possible to have two inputs or control buttons for two different actions inside the same controller related to Html.BeginForm?
In the following example, I want the Subscribe tab to trigger the Subscribe action on the controller. It works well. I want the Unsubscribe entry to trigger the Unsubscribe action. How to do it? TIA.
<% using (Html.BeginForm("Subscribe", "NewsLetter")) {%> <div class="editor-field"> <%= Html.TextBoxFor(model => model.EmailAdress) %> <%= Html.ValidationMessageFor( model => model.EmailAdress) %> </div> <div > <input type="submit" class="submit" value="Subscribe" /> <input type="submit" class="submit" value="Unsubscribe" /> </div> <% } %>
Update
Just more context to this question:
My NewsLetterController has two actions: Subscribe and unsubscribe, as shown below:
public class NewsLetterController : Controller { [HttpPost] public ActionResult Subscribe(NewsletterSubscriber subscriber) {
I was hoping I could trigger every action from the same Form element, but this seems to be wrong. How do I save an MVC pattern, but if possible, avoid scripting? Published HTML is part of the partial view displayed on the main page.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl <AkwiMemorial.Models.NewsletterSubscriber>" %> <h2><strong>Newsletter</strong></h2> <legend>Enter your email</legend> <% using (Html.BeginForm("Subscribe", "NewsLetter")) {%> <div class="editor-field"> <%= Html.TextBoxFor(model => model.EmailAdress) %> <%= Html.ValidationMessageFor(model => model.EmailAdress) %> </div> <div > <input type="submit" class="submit" name="sub" value="Subscribe" /> <input type="submit" class="submit" name="unsub" value="Unsubscribe" /> </div> <% } %>
source share