Is it possible to have two inputs, or button controls, trigger two different actions within the same controller bound to Html.BeginForm?
In the following example, I want the Subscribe input to call Subscribe action on the controller. This works well. I want the Unsubscribe input to call my Unsubscribe action. How do I make this happen? 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 posted below:
public class NewsLetterController : Controller
{
[HttpPost]
public ActionResult Subscribe(NewsletterSubscriber subscriber)
{
// do something
}
[HttpPost]
public ActionResult Unsubscribe(NewsletterSubscriber subscriber)
{
// do something
}
I was hoping that I can invoke each action from the same Form element, but this apparently is false. How do I still maintain the MVC pattern but avoid scripting if possible? The posted HTML is part of a partial view rendered 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>
<% } %>