I have a customer page where I can add/update a customer. On this page I have a partial view with it's own form to add/update a customer address. I put this in a partial view because I want to reuse it on other pages. When I open the modal and try to post from the form in the partial view, I would expect it to post to my AddressController but it hits my CustomerController.
Is it possible to do what I am trying to do? Or do I need to use ajax to call my method. If that is the case I'm not sure how to handle my json token, so I was hoping I can make it work like this.
Thanks!
Main Page
@model MyProject.Models.CustomerViewModel
<form asp-action="Create">
<div class="row">
<div class="col-md-6">
<h2 class="icon-customer">New Customer</h2>
</div>
<div class="col-md-6">
<div class="form-group pull-right">
<input type="submit" value="Create" class="btn btn-default" />
<a asp-action="Index" class="btn btn-default">Back to List</a>
</div>
</div>
</div>
<div class="spacer"></div>
<div class="form-horizontal">
<div class="form-group">
<label asp-for="Customer.FirstName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Customer.FirstName" class="form-control" />
<span asp-validation-for="Customer.FirstName" class="text-danger"></span>
</div>
</div>
</div>
</form>
<div id="addAddress">Add Address</div>
<div id='modalAddress' class='modal'>
<div class="modal-dialog">
<div class="modal-content">
@Html.Partial("../Address/Create.cshtml", Model.AddressViewModel)
</div>
</div>
</div>
Partial View (/Address/Create.cshtml)
@model MyProject.Models.AddressViewModel
<form asp-controller="Address" asp-action="Create">
<div class="row">
<div class="col-md-6">
<h2 class="icon-address">New Address</h2>
</div>
<div class="col-md-6">
<div class="form-group pull-right">
<button id="btnClose" type="button" data-dismiss="modal" aria-hidden="true">X</button>
<input type="submit" value="Create" class="btn btn-default" />
<a asp-action="Index" class="btn btn-default">Back to List</a>
</div>
</div>
</div>
<div class="spacer"></div>
<div class="form-horizontal">
<div class="form-group">
<label asp-for="Address.Address1" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Address.Address1" class="form-control" />
<span asp-validation-for="Address.Address1" class="text-danger"></span>
</div>
</div>
</div>
</form>