Without using javascript to redirect: If you put forms in your childβs views, sometimes if you specify the action name and controller name in the Beginform helper (inside the child view), this problem does not occur. for example, I changed the look of my child action as follows:
Before:
@using (Html.BeginForm()) { ... }
After:
@using (Html.BeginForm("InsertComment", "Comments", FormMethod.Post, new { id = "commentform" })) { ... }
Now you can put the RedirectAction command inside the "InsertComment" action, and everything will work.
Two forms in one page control:
1. Specify a name for the "Submit" button (each form) (example: "submitvalue")
form1:
<input type="submit" value="login" name="submitValue" class="btn btn-success pull-right" />
form2:
<input type="submit" value="register" name="submitValue" class="btn btn-success pull-right" />
2. Do two actions for these forms. (For example: "Registration" and "Login")
[HttpPost] public ActionResult Login(LoginVM model, string submitValue) { if (submitValue == "login") {
- If you click the register or enter the form button, both actions are called up, but with the expression "if" we determine which one is our goal.
source share