So within my view, I have:
<div id="createProductModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Create Product</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
@using (Html.BeginForm("Create", "Product", FormMethod.Post, new { id = "createProductForm", @class = "form-horizontal"}))
{
<div class="form-group">
<div class="col-md-4">
@Html.LabelFor(m => Model.Product.Name, new { @class = "control-label" })
</div>
<div class="col-sm-8">
@Html.TextBoxFor(m => Model.Product.Name, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-4">
@Html.LabelFor(m => Model.Product.IsActive, new { @class = "control-label" })
</div>
<div class="col-sm-8">
@Html.CheckBoxFor(m => Model.Product.IsActive, new { @class = "form-control" })
</div>
</div>
}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="$('#createProductForm').submit();">Add product</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
And then in my ProductsController
I have added an action like so:
[HttpPost]
public ActionResult Create(Product product)
{
return View();
}
But for some reason when clicking submit it redirects me to this URL:
http://localhost/Product/Create
And throws a 404 error like so:
The resource cannot be found.
I've not defined a route within the route configs surely this shouldn't matter?
Does anyone understand what i seem to be doing wrong?