2

I use two submit button. (asp.net mvc3 aplicattion)

I found how make it here: http://blog.maartenballiauw.be/post/2009/11/26/Supporting-multiple-submit-buttons-on-an-ASPNET-MVC-view.aspx

Where put this The MultiButtonAttribute class? In Controller?

Maybe is easiest way to make this.

3
  • You can put the class anywhere as long as there is a reference in the using for the controller.
    – Valamas
    Commented Nov 6, 2011 at 23:45
  • Depending on what you need, you may not have to use this. If your second button does not need variables from the form (for instance, it's a "create new row" button), then you can create a second form only for the second button. This makes it much simpler. Commented Nov 7, 2011 at 0:01
  • Ok, if I use button, how add to this Redicttoaction? I mean, if I press button i go to other side? Commented Nov 8, 2011 at 17:13

2 Answers 2

1

you can add it anywhere in application including Controller Folder

1
**//model**
    public class input_element
        {
         public string Btn { get; set; }
        }   

**//views**
    @using (Html.BeginForm())
    {
            <button type="submit" name="btn" value="verify">
             Verify data</button>
            <button type="submit" name="btn" value="save">
             Save data</button>    
            <button type="submit" name="btn" value="redirect">
                 Redirect</button>
    }

**//controller**

    public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";
            return View();
        }

        [HttpPost]
        public ActionResult About(input_element model)
        {
                if (model.Btn == "verify")
                {
                // the Verify button was clicked
                }
                else if (model.Btn == "save")
                {
                // the Save button was clicked
                } 
                else if (model.Btn == "redirect")
                {
                // the Redirect button was clicked
                } 
                return View();
        }
1
  • 1
    You are not answering the question that the OP asked here. Commented Feb 26, 2013 at 5:40

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.