Monday, January 16, 2012

How to handle multiple buttons in one form in ASP.NET MVC?


1.      Razor view:

@using (Html.BeginForm())

{

    <fieldset>

        <legend>Edit </legend>

        <div class="editor-label">

            @Html.LabelFor(model => model.ID)

        </div>

        <p>

            <input name ="button" type="submit" value="Save" />

            <input name ="button" type="submit" value="Reject" />

            <input name ="button" type="submit" value="Accept" />

            <input name ="button" type="submit" value="Complete" />

        </p>

    </fieldset>

}



2.  Controller

        [HttpPost]

        public ActionResult Edit(string button)

        {

            switch (button)

            {

                case "Save":

                    break;

            }

            return RedirectToAction("Index");

        }


No comments:

Post a Comment