1

I have two buttons on my cshtml page - Agree and Disagree - how can I easily pass back there values to my Controller so I can make a decision to either take them to Homepage or Log them back out.

So on my cshtml page I have...

    <input type="button" name='Agree' value="I Agree"
                   onclick="location.href='@Url.Action("DoAccept", "Home")'" />
    <input type="button" name='Delete' value="I Disagree"
                   onclick="location.href='@Url.Action("DoAccept", "Home")'" />

So In my Home Controller then I have a DoAccept method as below:

    public ActionResult DoAcceptTC()
    {
       //if( buttom clicked was Agree)
        return RedirectToAction(VIEW_HOMEPAGE);
       //else
      //return Logout page..  
    }

So My question is how can I easily get a value back to the controller method?

2 Answers 2

5

There's no much point in using inputs without html form hosting them. You could use form, or simple links

//view
@using(Html.BeginForm("DoAccept"))
{
     <button name="decision" value="agree">I Agree</button>
     <button name="decision" value="disagree">I disagree</button>
}

//controller
public ActionResult DoAcceptTC(string decision)
{
    //decision == "agree"
}
Sign up to request clarification or add additional context in comments.

Comments

2

You must send paramaters along with Url.Action to the controller so that you can be able to perform your actions easily. Below link may help you.

Url.Action with params

Comments

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.