How do i post the submit button to a different action?
@{ ViewBag.Title = "VehicleManagement"; } <h2>VehicleManagement</h2> <div> <h4>Vehicle Management System</h4> <hr /> <form action="Vehicle/VehicleManagement" method="post"> <input type="submit" value="Add Vehicle" onclick="location.href='@Url.Action("CreateVehicle","Vehicle")'"/> </form> </div>
public class VehicleController : Controller { // GET: Vehicle public ViewResult VehicleManagement() { return View("VehicleManagement"); } public PartialViewResult CreateVehicle() { return PartialView("VehicleEntry"); } }
Alternatively, you can use jquery as below
<button id="btnSubmit">Add Vehicle</button>
$(‘#btnSubmit’).on(‘click’, function (e) {
e.preventDefault();
window.location.href = "@(Url.Action("CreateVehicle", "Vehicle"))";
});