简体   繁体   中英

MVC ASP.NET Url.Action in form action, passing it form data

        <form action="@Url.Action("PokemonSteps", "PokemonView", new { id = Model.Id, steps = steps })">
            <input type="number" name="steps" min="1" max="@Model.userSteps">
            <input type="submit">
        </form>

This form is a number box from 1 to the amount of steps the user has. When they submit the number in the box, I want to pass it to @Url.Action as the steps in the steps = steps part.

How do I go about that (sorry for the really stupid question)

<form action="@Url.Action("PokemonSteps", "PokemonView")" method="post">
   <input type="hidden" name="id" value="@Model.Id">
   <input type="number" name="steps" min="1" max="@Model.userSteps">
   <input type="submit" value="Submit">
</form>

Please add Attribute method="post" and share your controller method signature also...

Try doing something like this:

@using (Html.BeginForm("PokemonSteps", "PokemonView", FormMethod.Post)){    
     @Html.TextBoxFor(m=> m.userSteps)
     <input type="submit" value="Submit" />
}

Hope this Helps!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM