0

I am new to MVC so I am still learning my way. I am submitting a form,and I need to grab the data of one of the textboxes and pass it to the URL. My Routeconfig is default so I know I have the route correctly, now this is my controller:

    AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Verify(string verificationString)
    {

        return View();
    }

And my view has this:

 @using(Html.BeginForm("Verify", "Status", FormMethod.Post)) {
     @Html.AntiForgeryToken()

@Html.TextBoxFor(m => m.verificationCode, new { @name="verificationID", @class = "form-control", @maxlength = "18", @required="required" })
 }

I don't know how to pass this variable in the URL so it shows /Status/Verify/verificationstring(textbox data). How can I do this?

EDIT: RouteConfig

 routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

EDIT: FullView

  @model LSFVerif.Models.StatusModel
 <div class='form-group' style="text-align:center">

  @using(Html.BeginForm("Verify", "Status", FormMethod.Post)) {
     @Html.AntiForgeryToken()
 @Html.ValidationSummary(true)

  @Html.TextBoxFor(m => m.Email, new { @class = "form-control", @type="email", @placeholder = "Email", @maxlength = "100", @required="required" })


 @Html.TextBoxFor(m => m.VerificationCode, new { @name="VerificationCode", @class = "form-control", @placeholder = "Codigo", @maxlength = "18", @required="required" })


          <button class='btn-lg btn-primary' type='submit'>Verify</button>

}

2 Answers 2

1
    @using (Html.BeginForm("Verify", "Status", FormMethod.Post))
    {
        @Html.AntiForgeryToken()

        @Html.TextBoxFor(m => m.verificationCode, new { @class = "form-control", @maxlength = "18", @required = "required" })
     <input type="submit" value="Submit" />
    }
and 

     [HttpPost]
     public ActionResult Verify(string verificationCode)
    {

          return RedirectToActionPermanent("Vierified", "Status", new
            {
                id = verificationCode
            });
    }

        [HttpGet]
        public ActionResult Vierified(string verificationCode)
        {
            return View("Vierified");
        }
Sign up to request clarification or add additional context in comments.

3 Comments

Tried both methods and whenever I submit I get the same URL. Just Status/Verify and nothing afterwards. Will post routeconfig just in case.
Added the View. Submit button is there, and it is passing the value not just showing the URL as it should. Button is inside the form.
The value is not showing in the URL because it's a post action. If you need to show use RedirectToActionPermanent - check the example i added.
0

Just update your parameters to this:

AcceptVerbs(HttpVerbs.Post)]
public ActionResult Verify(ThisShouldBeTheNameOfYourModel model)
{

    return View();
}

5 Comments

Hmm, changed to this but no go. Still get the same URL.
Look at the view, the name of the model is at the top of the page it will start with @model use that name and replace ThisShouldBeTheNameOfYourModel with the name of the model. Also make sure the name of the controller is StatusController. You do not need @name="verificationID", you do need a submit button.
Yes, the model is the same. I also have the submit button, just didn't post it. Maybe I am doing something wrong?
You have a break point @ the return View(); ? Is the page refreshing?
Yes, in fact it IS passing the parameter as I am getting the input in the variable, its just not showing that data in the URL itself.

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.