マイポストメソッドはヌルモデルオブジェクト(パラメータ)データポスト後になっています。 テキストボックスのすべての名前を確認しました。名前= "Indeksy [0] .min" ここでは多くのトピックを検索しようとしましたが、誰も助けてくれませんでした。 私はすべてのエラーを参照してくださいcan'yので、たぶん、あなたたちは、任意のアイデアを持っている:/ 事前のおかげで...投稿後MVCヌルリスト
ビュー:
@model AktualnyProjekt.Models.Glowna
<div id="widelki" hidden="hidden">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
for (var k = 0; k < Model.Indeksy.Count; k++)
{
@Html.HiddenFor(i => i.Indeksy[k].IndeksId)
<div class="form-group">
@Html.LabelFor(model => model.Indeksy[k].nazwa_rodzaju, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Indeksy[k].nazwa_rodzaju, new { @class = "form-control" })
@*@Html.TextBoxFor(model => item.nazwa_rodzaju, new { @class = "form-control", @readonly = "true" })*@
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Indeksy[k].poziom, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Indeksy[k].poziom, new { @class = "form-control" })
@*@Html.TextBoxFor(model => item.nazwa_rodzaju, new { @class = "form-control", @readonly = "true" })*@
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Indeksy[k].min, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Indeksy[k].min, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Indeksy[k].max, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Indeksy[k].max, new { @class = "form-control" })
</div>
</div>
}
}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Save" class="btn btn-default" />
</div>
}
</div>
モデル:
public class Glowna
{
//public IEnumerable<Log> Logs { get; set; }
public IList<Indeks> Indeksy { get; set; }
}
コントローラ:
[Authorize]
[HttpGet]
public ActionResult Index()
{
Glowna model = new Glowna();
model.Indeksy=db.Indeksy;
return (model);
}
[Authorize]
[HttpPost]
public ActionResult Index(Glowna model)
{
if(ModelState.IsValid)
{
if (model != null)
{
foreach (Indeks item in model.Indeksy)
{
Indeks inde = db.Indeksy.First(x => x.IndeksId == item.IndeksId);
inde.min = item.min;
inde.max = item.max;
}
db.SaveChanges();
}
}
return RedirectToAction("Index","Home");
}
することにより、この
を変更するには、どのような形のデータが送信されているクロムインスペクタのXHRで確認しました。モデルのGlownaにもリストプロパティが1つしかないようです。私があなただったら私は最初にpublic ActionResult Index(** FormCollection ** form)メソッドを試してから先に進んで –