【问题标题】:Passing Item ID to JS Function将项目 ID 传递给 JS 函数
【发布时间】:2018-01-17 14:33:41
【问题描述】:

我正在使用带有实体框架的 ASP.NET MVC 5。

目前我有一个侧面有按钮的桌子:

<table class="table">
    <tr>
        <th>
            @Html.ActionLink("Name", "DisplayAllAdmin", new { sortOrder = ViewBag.NameSortParm }, htmlAttributes: new { @class = "sortLabel" })
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Description)
        </td>
        <td>
            <a href="@Url.Action("Download", "Sth", new { id = item.Id }, null)"><i class="material-icons">get_app</i></a>
            <a href="@Url.Action("Delete", "Sth", new { id = item.Id }, null)"><i class="material-icons">delete</i></a>
        </td>
    </tr>

如何添加下一步按钮来显示记录详情?

现在我有这样的东西:

        <tr style="display:none">
            <td>@Html.DisplayFor(modelItem => item.TbVersion)</td>
        </tr>

    <script type="text/javascript" language="javascript">
        function DisplayDetails(id) 
        {

            if (document.getElementById("detailsField").style.display == "none")
            {
                document.getElementById("detailsField").style.display = "block";
            }

            else
            {
                document.getElementById("detailsField").style.display = "none"
            }
        }
    </script>

<button onclick="DisplayDetails(id)"><i class="material-icons">info</i></button>

但是我在传递 ID 时遇到了麻烦。有什么建议么?非常感谢。

【问题讨论】:

标签: javascript c# entity-framework asp.net-mvc-5


【解决方案1】:

尝试像这样设置参数

        <a href="@Url.Action('Delete', 'Sth', new { id = " + item.Id +  "}, null)"><i class="material-icons">delete</i></a>

【讨论】:

  • 但我不想重定向到另一个动作。我只想将详细信息滑到所选记录下。
  • 我以为你的问题是通过 id ?
猜你喜欢
  • 2022-07-21
  • 1970-01-01
  • 1970-01-01
  • 2019-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-25
相关资源
最近更新 更多