I have two forms on one page. In my first form I have all the field data (name, username, password, etc). In my second form I just have a button. Both forms on submission go to different actions in my controller.
Problem - when I submit form 2 from buton click, any fields from form 1 don't get passed to the controller via ViewModel. Ex. The action "ExternalLogin" doesn't get the "Gender" field value
How can I pass "Gender" from the first form to my second form before I submit the second form? JQuery? I tried putting HTML.HiddenFor(m => m.Gender) in my second form, but that didn't work.
Here is some sample code.
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", @id = "registerForm", role = "form", style = "margin-left: 20px" }))
{
<div id="formGroup1" class="form-group">
@Html.LabelFor(m => m.Gender, new { @id = "genderLabel" })
<div class="">
@Html.EnumDropDownListFor(m => m.Gender, new {@id = "genderId", @class = "selectpicker form-control" })
</div>
</div>
// other fields here
}
@using (Html.BeginForm("ExternalLogin", "Account", FormMethod.Post, new { ReturnUrl = Model.ReturnUrl, @id = "registerForm", role = "form", style = "margin-left: 20px" }))
{
<button type="submit" class="btn btn-default btn-lg" id="facebookButton" name="provider" value="Facebook" title="Log in using your Facebook account" style="width: 280px; color: white; background-color: #4c7bd9"><i class="fa fa-facebook" style="color: white"></i> Connect</button>
}
name
attribute and differentvalue
attributes. Then post to one method with a parameter from the button name and perform your logic based on the clicked button - user3559349