ASP.NET MVC 3を使用するWebアプリケーションでは、パラメーターとして初期化されたプロパティを持つモデルをコントローラーから部分ビューに渡します。
ビューには単一のテキストボックスを含むダイアログが表示され、送信時に開始コントローラーでアクションが実行されます(アクションはパラメーターと同じモデルタイプを取ります)。
問題は、この時点で、テキストボックスフィールドに関連するプロパティのみが値を持ち、その値はユーザーによって挿入され、他のすべてのプロパティは、ビューに適切な値があったとしてもnullであるということです。
送信ボタンがクリックされた後、プロパティをビューからコントローラーに保持するにはどうすればよいですか?
編集(追加されたコード):
//---------- 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)
...
}