[英]Why isn't my form posting back my td information?
So I'm trying to post back the value that's inside the <td>
but for some reason it's not posting it back, all the properties are either null or set to their default value such as 0.所以我试图回发
<td>
内的值,但由于某种原因它没有回发它,所有属性要么为空,要么设置为它们的默认值,例如 0。
It should post back the values when I click this button当我单击此按钮时,它应该回发值
<button type="submit" class="btn btn-icon waves-effect waves-light btn-info"> <i class="fa fa-wrench"></i> </button>
But for some reason it's not grabbing things like <td>@Html.DisplayTextFor(x => x.ServerID)</td>
and posting it back但出于某种原因,它没有抓取诸如
<td>@Html.DisplayTextFor(x => x.ServerID)</td>
并将其发回
Here is the razor这是剃须刀
@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>
}
And the Controller和控制器
public ActionResult Edit(ServerModel serverModel)
{
var model = serverModel;
return View();
}
the model properties are null or 0 as I said.正如我所说,模型属性为 null 或 0。
And here is the Model这是模型
public class ServerModel
{
public int ServerID { get; set; }
public string Endpoint { get; set; }
public bool IsRunning { get; set; }
}
Try尝试
@Html.HiddenFor(x => x.ServerID)
@Html.DisplayTextFor(x => x.ServerID)
DisplayTextFor will only render the item as text. DisplayTextFor 只会将项目呈现为文本。
Including the hidden field will include them in the payload sent to the server - as form items.包含隐藏字段会将它们包含在发送到服务器的有效负载中 - 作为表单项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.