Hello everyone, tell me who can please. There is an action method named Index in it at the end of the return View("Users") . That is, it returns the Users view. In this view, there is a form with a submit button. I expect that when you click on it, the form will be sent to the action named Users with all the data entered in the form. But she comes back to Index . How to make, that when sending, the filled form was sent to the Users action, and not in the Index ?? I tried this option <input type="submit" value="Add" formaction="Home/Users" />

    2 answers 2

    It would be necessary to see the code, where something that does not go there

     <input type="submit" value="Add" formaction="Home/Users" /> 

    here try to do so

     <input type="submit" value="Add" formaction="/Home/Users" /> 
    • one
      Sori, the code is not inserted. Where you have a formaction before the home put "/" - user183199
    • Thanks, it helped so much! I did not know that the slash works wonders - Polyakov Sergey

    I would have done something wrong. I assume that we use the class we need to develop the VisualStudio

     public class User { public string Title {get;set;} public string Description {get;set;} } 

    controller methods

     public ActionResult Edit(int id) { User model = service.GetUserById(id); return View(model); } [HttpPost] public ActionResult Edit(User model) { if(ModelState.IsValid) { ///необходимые действия return RedirectToAction("Index"); } return View(model) } 

    representation

     @model User @using (Html.BeginForm("Edit","Home", FormMethod.Post)) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>StateEditModel</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> } 

    Bootstrap is used for layout presentation.