私はMVCをかなり新しくしており、モデルバインディングに慣れようとしています。私はフォームで作成したシンプルなモデルを持っています。しかし、私はフォームを投稿するときにのみ、テキストボックスの値がコントローラに持ち越されています。 DisplayTextForを使用して記述フィールドも必要です。これはカスタムモデルのバインダーを作る必要があるのでしょうか?私は、ショートカットを取ることができますし、テキストだけのように見えるので、説明がテキストの境界線がないので、正しい方法をしたい。ここに私のコードは次のとおりです。MVC3はモデル全体を投稿していません
public class FullOrder
{
public List<FullOrderItem> OrderList { get; set; }
public string account { get; set; }
public string orderno { get; set; }
}
public class FullOrderItem
{
public int? ID { get; set; }
public int? OrderId { get; set; }
public string Description { get; set; }
public int Qty { get; set; }
public decimal? Price { get; set; }
}
はここで見る
<table class="ExceptionAltRow">
<tr style="background-color: #DDD;">
<td class="strong" style="width:500px;">
Description
</td>
<td class="strong" style="width:100px;">
Qty
</td>
<td class="strong" style="width:100px;">
Previous Purchases
</td>
</tr>
@for (int i = 0; i < Model.FullOrder.OrderList.Count(); i++)
{
<tr>
<td>
@Html.DisplayTextFor(m => m.FullOrder.OrderList[i].Description)
</td>
<td>
@Html.TextBoxFor(m => m.FullOrder.OrderList[i].Qty, new { @style = "width:50px;" })
</td>
</tr>
}
</table>
はここコントローラーです:
[HttpPost]
public ActionResult AddItem(FullOrder f)
{
//doesn't work description is not passed but qty is
}
は、私は私のモデルは単に渡すために得ることができる方法はあります私のモデルからテキストボックスのバインドされた項目ではないにもかかわらず、記事の説明?
おかげ説明値が含まれています送信されたフォーム。 – mscard02
答えが役に立つ場合は、上向きの矢印をクリックしてそのように示す必要があります。 –