0

I realise this is extremely elemetry but I would like to pass a text box value to a controller method when using Html.BeginForm

this is the what I tried so far

cshtml

@using (Html.BeginForm("GetPassword", "Home"))
{
    <div id="panEmailForgotPassword">
        <h3 style="margin: 0;">
            Please enter your email address</h3>
        <br />
        <table style="width: 57%; padding-bottom: 10px; height: 126px;">
            <tr>
                <td>
                    <label style="width: 110px;">
                        Email address:</label>
                </td>
                <td>
                    @Html.TextBoxFor(m => m.EmailForgotPassword, new { name = "txtEmailForgotPassword" })
                </td>
            </tr>

controller method

[HttpPost]
    public ActionResult GetPassword(string txtEmailForgotPassword)
    {
        ViewModel model = new ViewModel();

        model.VerifyUserExists(txtEmailForgotPassword);
        return View(model);
    }

txtEmailForgotPassword returns a null value.

How would I do this correctly?

Arian

1 Answer 1

4

I dont think there is need to pass single string paramater, rather you can pass your whole model from view

[HttpPost]
    public ActionResult GetPassword(YourModel yourmodel)
    {
        ViewModel model = new ViewModel();

        model.VerifyUserExists(yourmodel.EmailForgotPassword);
        return View(model);
    }
Sign up to request clarification or add additional context in comments.

3 Comments

ya no problem. everybody starts from nothing ;)
But i want one favour, ask your team to lose 1st test against our team hahaha ;)
Oh sure. I will talk to the captain. We are very close :-)

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.