Как получить входные значения из модального всплывающего окна загрузки из метода mvc 5, я вызываю метод с помощью кнопки click onclick, используя это:Как получить входные значения из загрузочного модального popoup в mvc 5 method
<button type="button" class="btn btn-blue" onclick="location.href = '@Url.Action("SaveToDb")';return false;">
public void SaveToDb(AddressViewModel addrs)
{
var addressLine1 = addrs.AddressLine1;
var addressLine2 = addrs.AddressLine2;
var city = addrs.City;
}
Моя форма:
<form role="form" class="form-horizontal" method="POST">
<!-- start: BOOTSTRAP EXTENDED MODALS -->
<div id="responsive" class="modal fade" tabindex="-1" data-width="760" style="display: none; top: 50px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title">Add Address</h4>
</div>
<div class="modal-body">
<div class="form-group">
@Html.LabelFor(model => model.ClientId, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ClientId, new { htmlAttributes = new { @class = "form-control", @ReadOnly = true } })
@Html.ValidationMessageFor(model => model.ClientId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.AddressLine1, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.AddressLine1, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.AddressLine1, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.AddressLine2, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.AddressLine2, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.AddressLine2, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.City, htmlAttributes : new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.City, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-light-grey">
Close
</button>
<button type="button" class="btn btn-blue" onclick="location.href = '@Url.Action("Savetodb")';return false;">
Save changes
</button>
</div>
</div>
</div>
<!-- ends: BOOTSTRAP EXTENDED MODALS -->
у меня есть точки останова в методе SaveToDB, но AddressViewModel объект (addrs) является нулевым во все дни. пожалуйста, любая помощь будет оценена по достоинству.
Непонятно, что вы ожидаете. Вы не отправляете форму или передаете какие-либо значения методу. –
Я только что включил свою модальную всплывающую форму – UwakPeter
Вам нужна кнопка отправки, чтобы отправить форму. И форма нуждается в атрибуте действия (используйте 'Html.BeginForm()', так что вы создаете html правильно (либо для использования jquery ajax для отправки формы) –