0
我的post方法在數據發佈後獲取null模型對象(參數)。 我檢查了所有文本框的名稱,它們是這樣的:name =「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");
}
改變這種
你在正在發送的表單數據的Chrome檢查XHR檢查。 Glowna模型似乎只有一個列表屬性。如果我是你,我會首先嚐試公共的ActionResult索引(** FormCollection **表格)方法,然後繼續前進 –