c# - 为什么我的表格没有发回我的 td 信息?
问题描述
所以我试图发回里面的值,<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 只会将项目呈现为文本。
包含隐藏字段会将它们包含在发送到服务器的有效负载中 - 作为表单项。
推荐阅读
- excel - 修改 VBA 代码以分别更改每行的单元格输入
- node.js - 使用节点将文件内容流式传输到标准输出
- couchbase - 无法部署 couchbase 事件功能
- url - 是否有规范的 webrtc 对等 URL 格式?
- r - 如何根据 R 中的条件更改整个表格值的字体颜色?
- r - 等长组
- amazon-web-services - Redshift GetClusterCredentials IAM 策略需要 DbName
- android - 打开 PDF-s、XLS、DOC 时事务过大
- html - 使我的网站具有响应性的问题
- angular - ngx-translate - 在 TypeScript 文件中翻译没有组件的键