我有一个客户页面,我可以在其中添加/更新客户。在这个页面上,我有一个部分视图,它有自己的表格来添加/更新客户地址。我把它放在局部视图中,因为我想在其他页面上重用它。当我打开模态并尝试从局部视图中的表单发布时,我希望它发布到我的AddressController,但它会命中我的CustomerController。
有可能做我想做的事吗?或者我是否需要使用ajax来调用我的方法。如果是这种情况我不知道如何处理我的json令牌,所以我希望我可以让它像这样工作。
谢谢!
主页
@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>
部分视图(/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>