issue with form C# asp.net mvc

You should create your view like :

@model Yournamespace.Models.ModelName


<div>
        @using (Html.BeginForm("MethodName", "ControllerName", FormMethod.Post, new { @class = "css class if any" }))
        {             
            <section>
                <div class="input-block">
                    <strong><label>yOur Label</label></strong>
                    @Html.EditorFor(model => Model.Attribute)
                    <div class="UserIdValidation">
                        @Html.ValidationMessageFor(model => Model.Attribute)
                    </div>
                </div>

                <p style="margin-top: 25px" class="input-block">
                    <input type="submit" value="Submit">
                </p>              
            </section> 
        }
</div>

and your controller action should be like this :

 public class ControllerNameController : Controller
 {
        [HttpPost]
        public ActionResult Login(ModelName model)
        {           

              return View("VewName");
        }
 }

Leave a Comment