MVC View Form – [.cshtml]
Following is the MVC form which contains two submit buttons:
- @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "form1" }))
- {
- @Html.TextBoxFor(m => m.Name, new { maxlength = 50 })
- <input type="submit" id="btnSubmit" name="command" value="Submit" />
- <input type="submit" id="btnReset" name="command" value="Reset" />
- }
Below method in your .cs page to determine the command name and then perform task according to the button’s command name.
- [HttpPost]
- public ActionResult Index(StudentModel model, string command)
- {
- if (command == "Submit")
- {
- //your "Submit" button code here..
- }
- else if (command == "Reset")
- {
- //your "Reset" button code here..
- }
- return View(model);
- }
No comments:
Post a Comment