我创建了一个名为 AddCust.cshtml 的弹出窗口。一旦用户点击 btnSaveConsumer 它应该拾取输入的所有值。但我不确定如何通过控制器。我尝试使用如下的 javascript,但它没有从 AddCust.cshtml 传递任何内容。请指教,谢谢
AddCust.cshtml
@model HHIMS_Web_App.Models.ConsumerModel
@{
}
<br />
<div>
<fieldset id="AddNewConsumer">
<br /> <br />
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.HRN)
@Html.EditorFor(model => model.HRN)
</div>
<div class="smallBox">
@Html.LabelFor(model => model.DOB)
@Html.EditorFor(model => model.DOB)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.GivenName1)
@Html.EditorFor(model => model.GivenName1)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.FamilyName1)
@Html.EditorFor(model => model.FamilyName1)
</div>
<div class="smallBox">
@Html.LabelFor(model => model.Ethnicity)
@Html.EditorFor(model => model.Ethnicity)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.GivenName2)
@Html.EditorFor(model => model.GivenName2)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.FamilyName2)
@Html.EditorFor(model => model.FamilyName2)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.Address)
@Html.EditorFor(model => model.Address)
</div>
<div class="smallBox">
@Html.LabelFor(model => model.CarerContactName)
@Html.EditorFor(model => model.CarerContactName)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.Community)
@Html.EditorFor(model => model.Community)
</div>
<div class="smallBox">
@Html.LabelFor(model => model.CarerContact)
@Html.EditorFor(model => model.CarerContact)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.State)
@Html.EditorFor(model => model.State)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.PostCode)
@Html.EditorFor(model => model.PostCode)
</div>
</div>
<div>
<div class="addConsumerInfo">
@Html.LabelFor(model => model.Phone)
@Html.EditorFor(model => model.Phone)
</div>
<div class="smallAddAndCancel">
<input type="button" id="btnCancel" style="height:33px; width:70px; font-size:14px; background-color:#3399FF" class="k-button" title="Cancel" value="Cancel" onclick="window.close()" />
<input type="button" id="btnSaveConsumer" style="height:33px; width:70px; font-size:14px; background-color:#3399FF" class="k-button" title="Save" value="Save" />
</div>
</div>
</fieldset>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#btnSaveConsumer').click(function () {
var hrn;
var community;
var ethnicity;
var familyName;
var givenName;
if (hrn) {
$filter.push({ field: "HRN", operator: "contains", value: hrn });
}
if (community) {
$filter.push({ field: "Community", operator: "contains", value: community });
}
if (familyName) {
$filter.push({ field: "FamilyName", operator: "contains", value: familyName });
}
if (givenName) {
$filter.push({ field: "GivenName", operator: "contains", value: givenName });
}
if (ethnicity) {
$filter.push({ field: "Ethnicity", operator: "contains", value: ethnicity });
}
$.ajax({
type: 'POST',
url: "@(Url.Content("~/ConsumerDetails/CreateConsumerList/"))",
data: {
"HRN": hrn,
"Community":community,
"FamilyName1":familyName,
"GivenName1":givenName,
"Ethnicity":ethnicity,
},
});
});
});
</script>
控制器:
[HttpPost]
public ActionResult CreateConsumerList(ConsumerModel model)
{
if (ModelState.IsValid)
{
HHIMS_DataAccessLayer.Consumers dalModel = new HH.Consumers();
Mapper.CreateMap<ConsumerModel, HH.Consumers>();
Mapper.Map(model, dalModel);
dbConsumer.SaveConsumer(dalModel);
}
return RedirectToAction("Index");
}