这是我的模特:
public class RegistryItemModel
{
public string uuid { get; set; }
public int version { get; set; }
public string form { get; set; }
public int formVersion { get; set; }
public string modified { get; set; }
public string nodeUUID { get; set; }
public List<RegistryItemValue> data { get; set; }
}
我只需要更新数据道具。这是班级:
public class RegistryItemValue
{
public string id { get; set; }
public string type { get; set; }
public string label { get; set; }
public string value { get; set; }
public string key { get; set; }
public string valueID { get; set; }
}
然后是观点:
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
@model SWG_ArtaAPI.Models.RegistryItemModel
@using (Html.BeginForm("Save", "RegistryItem", FormMethod.Post))
{
<div class="form-group">
<h3>@ViewBag.Title</h3>
<table border="0">
@for (var i = 0; i < Model.data.Count; i++)
{
<tr>
@if (@Model.data[i].label != null)
{
<td><label>@Model.data[i].label</label></td>
}
@switch (@Model.data[i].type)
{
case "textbox":
<td>@Html.TextBoxFor(m => m.data[i].value)</td>
break;
}
</tr>
}
</table>
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Отправить" class="btn btn-default" />
</div>
</div>
}
</body>
</html>
视图显示我的数据就好了,我在输入字段中获取值并可以更改它们。但是当我尝试在我的post方法中保存它(提交)时,我将我的模型类的所有道具设置为null。以下是它的定义:
[HttpPost]
public string Save(RegistryItemModel model)
我的代码出了什么问题?为什么我总是变空? Here's how it looks