0
在使用ASP.NET MVC 3的Web应用程序中,我从控制器传递一个模型,并将初始化属性作为参数传递给局部视图。部分视图返回带有空字段的模型
该视图显示一个带有单个文本框的对话框,并在启动控制器中提交动作时被触发(该动作与参数具有相同的模型类型)。
问题是,在这一点上,只有相对于文本框字段的属性有一个值,即用户插入的值,而所有其他值为空,即使在视图中它们具有适当的值。
一旦提交按钮被点击,我怎样才能将视图中的属性保存到控制器?
编辑(添加的代码):
//---------- This method in the controller call the Partial View and pass the model --------
[HttpPost]
public PartialViewResult GetAddCustomFormerClubDialog()
{
var order = GetCurrentOrder();
//Order has here all properties initialized
var dialogModel = new dialogModel<Order> { Entity = order, ControllerAddEntityActionName = "SelectOrder"};
return PartialView("Dialogs/AddOrder", dialogModel);
}
//----------------- Here the Partial View -----------------------------------
@model FifaTMS.TMS.Presentation.Model.Wizard.WizardDialogModel<Club>
<div>
@using (Ajax.BeginForm(Model.ControllerAddEntityActionName, "Orders", new AjaxOptions { HttpMethod = "POST"}))
{
@Html.LabelFor(a => a.Entity.Name)
@Html.TextBoxFor(a => a.Entity.Name, new { @class = "isrequired", style="width: 250px;" })
}
</div>
//-------- Here the method from the view (in the same controller as the first code portion) -----
[HttpPost]
public JsonResult SelectOrder(dialogModel<Order> OrderModel)
{
var order= OrderModel.Entity;
// But order has only the property Name set (in the view)
...
}
请张贴您的标记。我有一种感觉,你没有将数据绑定到你的模型,因为这些数据不在页面上。 – Gromer