簡體   English   中英

為什么我的表單不回發我的 td 信息?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM