我在局部视图中有一个表格正在正确地展示我想要的数据。但是,在提交表单时,传递给控制器的模型为空。我不确定是否因为它处于局部视图中,所以一切似乎都适合我。
部分视图
@model CustomerPickUp.Web.Models.SalesOrderModel
<h3 id="resultHeader">Search Results</h3>
<div id="resultsContainer">
<div id="container">
<table class="resultTable">
@using (Html.BeginForm("UpdateQueue", "Order", FormMethod.Post, new {id = "updateQueueForm"}))
{
@Html.ValidationSummary(true)
for (var i = 0; i < Model.SalesOrderList.Count(); i++)
{
<tr>
<td>
@Html.CheckBoxFor(it => Model.SalesOrderList[i].IsSelected)
</td>
<td style="text-align: right;">
@Html.Label("CustomerName", "Customer Name: ")
<br/>
@Html.Label("OrderNumber", "Order Number: ")
</td>
<td style="text-align: left;">
@Html.DisplayFor(it => Model.SalesOrderList[i].CustomerName)
@Html.HiddenFor(it => Model.SalesOrderList[i].CustomerName)
<br/>
@Html.DisplayFor(it => Model.SalesOrderList[i].OrderNumber)
@Html.HiddenFor(it => Model.SalesOrderList[i].OrderNumber)
</td>
</tr>
}
}
</table>
</div>
</div>
<div class="searchTypeSelection">
@(Html.Kendo().Button()
.Name("saveButton")
.Content("Add to Queue")
.HtmlAttributes(new {@class = "medium-btn"})
.Events(e => e.Click("save_Clicked"))
)
</div>
控制器
public ActionResult UpdateQueue(SalesOrderModel SALESorder)
{
if (SALESorder.SalesOrderList != null)
{
foreach (SalesOrder item in SALESorder.SalesOrderList)
{
if (item.IsSelected)
{
AddToOrderQueue(item);
}
}
}
return RedirectToAction("Orders");
}
主视图
@{
Layout = "~/Views/Shared/_CurrentQueueLayout.cshtml";
}
<div id="searchControls">
@using (Ajax.BeginForm("ProcessSearch", "Search", new AjaxOptions { UpdateTargetId = "resultSection" }, new { id = "searchForm", @class = "pure-Form" }))
{
<div class="searchTypeSelection">
@(Html.Kendo().DropDownList()
.Name("searchOption")
.DataTextField("Text")
.OptionLabel("Search By...")
.DataValueField("Value")
.BindTo(new List<SelectListItem>()
{
new SelectListItem()
{
Text = "SO Number",
Value = "2"
},
new SelectListItem()
{
Text = "Phone Number",
Value = "1"
}
})
)
<br />
<br />
<input type="text" id="searchString" name="searchString" disabled="disabled" />
@(Html.Kendo().Button()
.Name("searchButton")
.Content("Search")
.Events(e => e.Click("search_clicked"))
.HtmlAttributes(new { @class = "medium-btn" })
)
</div>
}
</div>
<div id="resultSection">
</div>
<script type="text/javascript">
$(document).ready(function () {
//clear all fields
$("#searchString").val("");
$("#searchString").attr("disabled", "disabled");
});
$("#searchOption").change(function () {
var dropdownlist = $("#searchOption").data("kendoDropDownList");
var index = parseInt($("#searchOption").val());
alert(index);
if (dropdownlist.value() == 2) {
$("#searchString").inputmask("************");
$("#searchString").val("");
$("#searchString").removeAttr("disabled");
} else if (dropdownlist.value() == 1) {
$("#searchString").inputmask("999-999-9999");
$("#searchString").removeAttr("disabled");
$("#searchString").val("");
} else {
$("#searchString").attr("disabled", "disabled");
$("#searchButton").addClass("mobileButtonDisabled");
}
});
$('#searchString').on('input', function () {
var maskedtextbox = $("#searchString").val();
var dropdownlist = $("#searchOption").data("kendoDropDownList");
if ((dropdownlist.value() == 1 || dropdownlist.value() == 2) && maskedtextbox != "") {
$("#searchButton").removeClass("mobileButtonDisabled");
} else {
$("#searchButton").addClass("mobileButtonDisabled");
}
});
function search_clicked(e) {
e.preventDefault();
$("#searchForm").submit();
};
function save_Clicked(e) {
e.preventDefault();
$("#updateQueueForm").submit();
};
</script>
更新
我更改了该操作的签名,但这并没有改变任何内容。在查看生成的HTML后,我注意到我的元素没有在表单中呈现。关于为什么的任何想法?
<form id="updateQueueForm" method="post" action="/Order/UpdateQueue"> </form>
<tbody>
<tr>
<td>
<td style="text-align: right;">
<td style="text-align: left;">
<td>
<td style="text-align: right;">
<td style="text-align: left;">
答案 0 :(得分:0)
您在局部视图控制器中使用了错误的代码
public PartialViewResult UpdateQueue(SalesOrderModel SALESorder)
{
//
}
也不确定您的按钮最好使用html提交按钮
答案 1 :(得分:0)
似乎表格元素我包含的表格是原因。我确信我之前已经这样做了,但无论如何最好以正确的方式做到这一点。谢谢你的帮助,以及我最终改变的内容。
<div id="container">
<div class="table">
@using (Html.BeginForm("UpdateQueue", "Order", FormMethod.Post, new { id = "updateQueueForm", @class = "row" }))
{
@Html.ValidationSummary(true)
for (var i = 0; i < Model.SalesOrderList.Count(); i++)
{
<div class="cell">
@Html.CheckBoxFor(it => Model.SalesOrderList[i].IsSelected)
</div>
<div class="cell" style="text-align: right;">
@Html.Label("CustomerName", "Customer Name: ")
<br />
@Html.Label("OrderNumber", "Order Number: ")
</div>
<div class="cell" style="text-align: left;">
@Html.DisplayFor(it => Model.SalesOrderList[i].CustomerName)
@Html.HiddenFor(it => Model.SalesOrderList[i].CustomerName)
<br />
@Html.DisplayFor(it => Model.SalesOrderList[i].OrderNumber)
@Html.HiddenFor(it => Model.SalesOrderList[i].OrderNumber)
</div>
}
}
</div>
</div>