I want to pass an input model from a partial view to a controller. I'm rather new to MVC so still trying to understand how the default model binder works.
Via AJAX (listBox) a controller passes back a partial view and inserts into table id=searchResults.
@model ViewModels.LocationViewModel
@using (Ajax.BeginForm("ProcessSearch", "SearchR", new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "searchResults",
}))
{
<div>@Html.ListBoxFor(xxx)</div>
<input id="Search" type="submit" value="Search" />
}
Here is the controller and ViewModel that populates the partial view
public class OrderViewModel
{
public string Description { get; set; }
public string Status { get; set; }
}
public ActionResult ProcessSearch(SearchViewModel search)
{
select new OrderViewModel{
Status=f.STATUS,
Description=f.DESCRIPTION}).ToList();
return PartialView(model);
}
同じメイン ビューに、さらに別のビュー モデルにバインドしたいフォームがあります。部分ビューのモデルからデフォルトのバインダーを実装する方法がわかりません。これを正しく説明していない場合は、お詫び申し上げます。それが理にかなっていることを願っています。
@using (Html.BeginForm("Testing", "SearchR", FormMethod.Post))
{
<div>@Html.DropDownListFor(yyy)</div>
<input id="Reshop" type="submit" value="Reshop" />
}
<table id="searchResults"></table>
public ActionResult Testing(RSOrderViewModel rOrder)
{
return Content("hey");
}
public class RSOrderViewModel
{
public string yyy { get; set; }
public IEnumerable<OrderViewModel> sovm { get; set; }
}
@model List<ViewModels.OrderViewModel>
@{ViewData.TemplateInfo.HtmlFieldPrefix = "sovm";
}
<table id="searchResults">
<tr>
<th>Order Id</th>
<th>Order Detail</tr>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@Html.DisplayFor(x => x[i].OrderId)
</td>
<td>
@Html.DisplayFor(x => x[i].OrderDetail)
</td>
</tr>
}
</table>