[英]Why isn't my form posting back my td information?
所以我试图回发<td>
内的值,但由于某种原因它没有回发它,所有属性要么为空,要么设置为它们的默认值,例如 0。
当我单击此按钮时,它应该回发值
<button type="submit" class="btn btn-icon waves-effect waves-light btn-info"> <i class="fa fa-wrench"></i> </button>
但出于某种原因,它没有抓取诸如<td>@Html.DisplayTextFor(x => x.ServerID)</td>
并将其发回
这是剃须刀
@using (Html.BeginForm("Edit", "Dashboard"))
{
<table class="table table-hover mb-0">
<thead>
<tr>
<th>#</th>
<th>Server Name</th>
<th>Credentials</th>
<th>Status</th>
<th>Modify</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td>@Html.DisplayTextFor(x => x.ServerID)</td>
<td>Data</td>
<td>@Html.DisplayTextFor(x => x.Endpoint)</td>
if (Model.IsRunning)
{
<td><span class="badge badge-success">Running</span></td>
}
else
{
<td><span class="badge badge-danger">Stopped</span></td>
}
<td>
<button class="btn btn-icon waves-effect waves-light btn-success"> <i class="fa fa-power-off"></i> </button>
<button class="btn btn-icon waves-effect waves-light btn-danger"> <i class="fa fa-stop"></i> </button>
<button type="submit" class="btn btn-icon waves-effect waves-light btn-info"> <i class="fa fa-wrench"></i> </button>
</td>
<td>
<button class="btn btn-icon waves-effect waves-light btn-danger"> <i class="fa fa-trash"></i> </button>
</td>
</tr>
</tbody>
</table>
}
和控制器
public ActionResult Edit(ServerModel serverModel)
{
var model = serverModel;
return View();
}
正如我所说,模型属性为 null 或 0。
这是模型
public class ServerModel
{
public int ServerID { get; set; }
public string Endpoint { get; set; }
public bool IsRunning { get; set; }
}
尝试
@Html.HiddenFor(x => x.ServerID)
@Html.DisplayTextFor(x => x.ServerID)
DisplayTextFor 只会将项目呈现为文本。
包含隐藏字段会将它们包含在发送到服务器的有效负载中 - 作为表单项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.