0

I want to call the same class from different buttons. Here is what I am doing:

<div class="buttondiv">
  @using (Html.BeginForm("TankList","Forms", FormMethod.Post))
  {
    <input class="allformsbutton" type="submit" value="ASME Basic Form" id="buttonAsmeBasic" />
  }
</div>

<div class="buttondiv">
  @using (Html.BeginForm("TankList", "Forms", FormMethod.Post))
  {
    <input class="allformsbutton" type="submit" value="ASME Detailed Form" id="buttonAsmeDetailed" />
  }
</div>

I want to pass to the class that I'm calling "TankList" which button was clicked.

How would I capture that in the class?

EDIT

I wanted to clarify. The point of the buttons is to uniquely identify which button was pressed. So, I want to pass to the TankList the value "ASME Basic Form" if the ASME Basic button was pressed or pass "ASME Detailed Form" if the ASME Detailed button was pressed.

1 Answer 1

3

your .cshtml-file:

<div class="buttondiv">
    @using (Html.BeginForm("TankList","Home", FormMethod.Post))
    {
        <input name="theClass" class="allformsbutton" type="submit" value="ASME Basic Form" id="buttonAsmeBasic" />
    }
</div>

<div class="buttondiv">
    @using (Html.BeginForm("TankList", "Home", FormMethod.Post))
    {
        <input name="theClass" class="allformsbutton" type="submit" value="ASME Detailed Form" id="buttonAsmeDetailed" />
    }
</div>

your FormsController.cs

public class FormsController : Controller
{
    [HttpPost]
    public void TankList(string theClass)
    {

    }
}

When you post the form the result in the controller is as follows depending on the button you clicked:

enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Nevermind on my previous response, I missed changing the class name. Perfect answer. Tyvm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.