试图编辑一个对象, 当我将模型提交给控制器时,从编辑视图中,它没有通过。 下面列出了我的代码、视图、模型和控制器,以及来自调试器的图片 视图
@model List<ABB.VERA.Core.Controllers.IOListObject>
@using (html.beginform())
{
<div class="form-group row">
<div class="col-md-offset-2 col-md-2 button">
<input type="submit" value="Spara" class="btn btn-default" />
</div>
<div class=" col-md-2 button">
@Html.actionLink("Avbryt","Index")
</div>
</div>
for (int i = 0; i < Model.Count; i++)
{
if (!(@Model[i].Key == "Id"))
{
<div class="form-group">
@Html.Label(@Model[i].Key,htmlAttributes: new { @class = "control-label col-md-2" })
@Html.HiddenFor(Model => @Model[i].Key)
@Html.EditorFor(Model => @Model[i].Value)
</div>
}
}
}
型号
public class IOListObject
{
public string Key { get; set; }
public string Value { get; set; }
public string dataTypeAsString { get; set; }
}
控制器
public actionResult Edit(List<IOListObject> model,string listName)
{
if (ModelState.IsValid)
{
//string listName = "";
var rowId = model.FirstOrDefault(d => d.Key == "Id");
var rowListName = model.FirstOrDefault(d => d.Key == "ListName");
var rowTested = model.FirstOrDefault(d => d.Key == "Tested");
var rowColumnName = model.FirstOrDefault(d => d.Key == "testColmn");
var rowobjectname = model.FirstOrDefault(d => d.Key == "objectname");
}
return RedirectToaction("Index",new { listName = _listName });
}