私はモデルを持っています(下を参照)。ユーザーは単一の支出の詳細を見ることができるはずです(すでにajaxで作業中で、ドロップダウン駆動です)。支出の詳細が読み込まれたら、その詳細の合計金額を入力するか、カテゴリ別に分割することができます(別々のモデル(SpendCategories)からのものです)。私は最初にそれらを元に戻すためにカテゴリを繰り返し、SpendCategoryNameをSpendBreakdown.csのSpendCategoryにマップします。 SpendCategory名ごとにテキストエリアを繰り返して生成し、モデル全体(予算)を返送しようとしています。私はこれを実行すると、それはループの中HiddenForライン上の範囲execeptionのうち、私に引数を与えビューからコントローラへのアイテムのリストをモデルとして戻すにはどうすればいいですか?
問題。私はちょうどポストに金額とカテゴリを保存する方法が必要です。残念ながら、私はMVCを初めとしており、モデルの設定方法を変更することはできません。この作品以外はすべて動作しています。
私は
public int SpendId {get; set;}
public List<SpendCategories> SpendCategories {get; set;}
Spend.csプライバシーの目的のために、このの一部を下にスクラブしなければならなかったが、私に知らせてください、あなたが明確化が必要な場合
モデル
public class Budgets : Financials
{
public Spend Spending { get; set; }
public SpendDetails SpendingDetails { get; set; }
public List<SpendBreakdown> SpendingBreakdown{ get; set; }
}
SpendCategories.cs(この部分的であるとしている呼んでいるメインページのPRE人口DATA)
public int SpendCategoryId {get; set;}
public string SpendCategoryName {get; set;}
public string SpendCategoryDescription {get; set;}
SpendDetails.cs
public int SpendDetailsId {get; set;}
public int SpendId {get; set;}
public string SpendDetailName {get; set;}
public int SpendBreakdownId {get; set;}
public decimal TotalSpendAmount {get; set;}
SpendBreakdown.cs
public int SpendBreakdownId {get; set;}
public int SpendDetailsId {get; set;}
public decimal SpendBreakdownAmount {get; set;}
public string SpendCategory {get; set;}
パーシャルビュー送信フォーム
<div class="row col-md-5">
<div class="table-responsive">
<table class="table-bordered">
<thead>
<tr>
<th class="dt-head-center">Category:</th>
<th>Total Amount: </th>
</tr>
</thead>
<tbody>
<tr>
<td>@Html.DisplayFor(model => model.SpendDetails.SpendCategories)</td>
<td>@Html.TextAreaFor(model => model.SpendDetails.TotalSpendAmount)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row totals">
<div class="table-responsive col-md-6">
<table class="table table-bordered table-condensed table-responsive" id="tblSpendSummary" summary="Spend Summary" style="padding-left: 10px;">
<thead>
<tr class="summary-header">
<th class="dt-head-center">Spend Category Name</th>
<th class="dt-head-center">Spend Breakdown Amount</th>
</tr>
</thead>
<tbody>
@foreach (var cat in Model.Spend.SpendCategories)
{
<tr>
<td>@cat.SpendCategoryName- @cat.SpendCategoryDescription</td>
@for (int i = 0; i < Model.Spend.SpendCategories.Count(); i++)
{
@Html.HiddenFor(model => model.SpendBreakdown[i].SpendCategory, new { @Value = @cat.SpendCategoryDescription })
@*@Html.HiddenFor(model => model.SpendBreakdown[i].SpendBreakdownId)*@
<td>@Html.TextAreaFor(model => model.SpendBreakdown[i].SpendBreakdownAmount)</td>
}
</tr>
}
</tbody>
</table>
</div>
</div>
コントローラ(ドロップダウンリストの変更あなたは、インデックスのためにSpendCategories
のCount
を使用している
public ActionResult BudgetTotalAmount(int spendDetailsId)
{
var SpendId = _executionRepository.RetrieveSpendIdBySpendDetailsId (spendDetailsId).SpendId;
var model = new Budgets
{
Spending = _executionRepository.RetrieveSpendIdBySpendDetailsId(spendDetailsId),
SpendingDetails = _executionRepository.RetrieveSpendSpendDetailsBySpendDetailsId(spendDetailsId),
SpendingBreakdown = _executionRepository.RetrieveSpendBreakdown(spendId, spendDetailsId)
};
return PartialView("Budgets/_SpendBudgetsTotalAmounts", model);
}
コントローラアクションメソッドがモデルを受信していますか?または何? –
@devlincarnate現在のところ、FORループの下の最初の行の範囲外の例外を取得しています。私はこの前に1つのカテゴリで公のList SpendingBreakdownがリストされた前にそれを試してみました。しかし今、SpendingBreakdownは私が問題を抱えているリストです –
cxwilson