Razor 将数据从视图传递到控制器时出错
这是我的控制器动作方法Razor 将数据从视图传递到控制器时出错,razor,model-view-controller,Razor,Model View Controller,这是我的控制器动作方法 [HttpPost] public ActionResult UpdateOrder(List<State> objState) { DataTable dst_state = new DataTable(); dst_state.Columns.Add("state_id", typeof(int)); dst_state.Columns.Add("sta
[HttpPost]
public ActionResult UpdateOrder(List<State> objState)
{
DataTable dst_state = new DataTable();
dst_state.Columns.Add("state_id", typeof(int));
dst_state.Columns.Add("state_order_by", typeof(int));
foreach (var abc in objState)
{
DataRow dr = dst_state.NewRow();
dr["state_id"] = abc.state_id;
dr["state_order_by"] = abc.state_order;
dst_state.Rows.Add(dr);
}
State.UpdateOrderState(dst_state);
TempData["message"] = "Order Updated Successfully";
return View("ViewState");
}
[HttpPost]
公共操作结果更新顺序(列表对象状态)
{
DataTable dst_state=新DataTable();
添加(“state_id”,typeof(int));
添加(“state_order_by”,typeof(int));
foreach(对象状态中的变量abc)
{
DataRow dr=dst_state.NewRow();
dr[“state_id”]=abc.state_id;
dr[“state_order_by”]=abc.state_order;
dst_state.Rows.Add(dr);
}
State.UpdateOrderState(dst_状态);
TempData[“message”]=“订单更新成功”;
返回视图(“视图状态”);
}
这是我的看法
@model dsmanager.Models.State
@using PagedList.Mvc;
@using dsmanager.Controllers;
@using dsmanager.DLL;
@using (Html.BeginForm("UpdateOrder", "State", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
Html.AntiForgeryToken();
Html.EditorForModel();
ViewBag.Title = "View State";
@*<script type="text/javascript">
function GetList() {
var active = "0"
var inactive = "0"
$("#loading").show();
var param = { active: active, inactive: inactive }
$.ajax({
type: 'POST',
dataType: 'html',
url: '/State/GetStateData',
data: param,
success: function (Data) {
$("#loading").hide();
$("#divpartialTable").empty();
$("#divpartialTable").html(Data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$("#loading").hide();
}
});
}
</script>*@
<section class="content-header">
<h1>State Details</h1>
<ol class="breadcrumb">
<li>
<a href="@Url.Action("InsertState", "State")" class="btn btn-danger"><i class="fa fa-plus"> Add</i></a>
</li>
</ol>
</section>
<div>@Html.DropDownListFor(model => model.state_country_id, Model.Country, "Please Select", new { onchange = "GetList();", @class = "form-control" } ) </div>
<br />
<div>@Html.TextBoxFor(model => model.state_name , new { @class = "form-control" })</div>
<br />
@*<a id="btnSearch" href="@Url.Action("ViewState", "State")" class="btn btn-danger"><i class="fa fa-plus"> Search</i></a>*@
<div class="screen-small">
<section class="content">
<div id="divgrid">
<div id="Addgrid" class="row">
<div class="col-xs-12">
<div class="box box-primary">
<div class="box-header with-border">
</div>
<div class="box-body no-padding">
<div>
</div>
<div class="resp-table">
<div>
<table class="table table-striped" cellspacing="0" cellpadding="0" style="border-width:0px;width:100%;border-collapse:collapse">
<thead>
<tr class="th" style="white-space:nowrap;">
<th scope="col">Edit</th>
<th scope="col">ID</th>
<th class="text-left" align="left" scope="col">State Name</th>
<th class="text-left" align="left" scope="col">Country</th>
<th class="text-left" align="left" scope="col">Status</th>
<th class="text-left" align="left" scope="col">Order</th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.pagedlist.Count; i++)
{
<tr valign="top">
<td class="text-center" width="20px" data-title="Edit"><a href="@Url.Action("EditState", "State", new { id = Model.pagedlist[i].state_id.ToString() } )"><i class="fa fa-pencil" title="edit"></i>E</a></td>
<td class="text-center" width="20px" data-title="ID">@Html.DisplayFor(model => model.pagedlist[i].state_id)</td>
<td class="text-center" width="100px" style="text-align:left" data-title="ID">@Html.DisplayFor(model => model.pagedlist[i].state_name)</td>
<td class="text-center" width="100px" style="text-align:left" data-title="ID">@Html.DisplayFor(model => model.pagedlist[i].country_name)</td>
<td class="text-center" width="100px" style="text-align:left"> @(Html.DisplayFor(model => model.pagedlist[i].state_status).ToString() == "1" ? "Active" : "Inactive")</td>
<td class="text-center" width="100px" style="text-align:left" data-title="ID">@Html.TextBoxFor(model => model.pagedlist[i].state_order)</td>
<td style="display:none">@Html.HiddenFor(model => model.pagedlist[i].state_id)</td>
</tr>
}
</tbody>
<tr class="th" style="white-space:nowrap;">
<td width="20px"></td>
<td width="20px"></td>
<td width="100px"></td>
<td width="100px"></td>
<td width="100px"></td>
<td class="text-left" width="100px">
<input type="submit" value="Update Order" class="btn btn-default" />
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="box-footer text-right">
@*Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount*@
@Html.PagedListPager(Model.pagedlist, page => Url.Action("ViewState", new { page }))
</div>
</div>
</div>
</div>
</div>
</section>
</div>
}
<br
/>
@model dsmanager.Models.State
@使用PagedList.Mvc;
@使用dsmanager.Controller;
@使用dsmanager.DLL;
@使用(Html.BeginForm(“UpdateOrder”,“State”,FormMethod.Post,new{enctype=“multipart/formdata”}))
{
Html.AntiForgeryToken();
Html.EditorForModel();
ViewBag.Title=“查看状态”;
@*
函数GetList(){
var active=“0”
var inactive=“0”
$(“#加载”).show();
var param={active:active,inactive:inactive}
$.ajax({
键入:“POST”,
数据类型:“html”,
url:“/State/GetStateData”,
数据:param,
成功:功能(数据){
$(“#加载”).hide();
$(“#可分割”).empty();
$(“#可分割”).html(数据);
},
错误:函数(XMLHttpRequest、textStatus、errorshown){
$(“#加载”).hide();
}
});
}
*@
详细说明
@Html.DropDownListFor(model=>model.state\u country\id,model.country,“请选择”,新建{onchange=“GetList();”,@class=“form control”})
@TextBoxFor(model=>model.state_name,new{@class=“form control”})
@**@
编辑
身份证件
州名
国家
地位
命令
@对于(int i=0;imodel.pagedlist[i].state\u id)
@DisplayFor(model=>model.pagedlist[i].state\u name)
@Html.DisplayFor(model=>model.pagedlist[i].country\u name)
@(Html.DisplayFor(model=>model.pagedlist[i]。state_status)。ToString()==“1”?“活动”:“非活动”)
@Html.TextBoxFor(model=>model.pagedlist[i].state_order)
@Html.HiddenFor(model=>model.pagedlist[i].state\u id)
}
@*@Model.PageCount的@页(Model.PageCountUrl.Action(“ViewState”,new{page}))
}
当将数据从视图传递到控制器以更新订单列时,我在控制器中得到空列表。如何读取控制器中的两个字段以更新顺序。请提供帮助。控制器操作的参数不正确
public ActionResult UpdateOrder(dsmanager.Models.State model)
model.state_country_id