【问题标题】:Pass a parameter from mvc webgrid从 mvc webgrid 传递参数
【发布时间】:2017-12-25 23:24:52
【问题描述】:

下面是我的 MVC WebGrid 代码

@ var grid = new WebGrid(source: Model, canPage: true, rowsPerPage: 5、canSort: true);

@grid.GetHtml(columns: grid.Columns(
       grid.Column(header: "#",
       format: item => item.WebGrid.Rows.IndexOf(item) + 1 + Math.Round(Convert.ToDouble(grid.TotalRowCount / grid.PageCount) / grid.RowsPerPage) * grid.RowsPerPage * grid.PageIndex),
       //format: item => item.WebGrid.Rows.IndexOf(item) + 1),
       grid.Column(header: "Full Name", columnName: "full_name",canSort:false),
       grid.Column(header: "User Name", columnName: "user_name", canSort: false),
       grid.Column(header: "Password", columnName: "password", canSort: false),
       grid.Column(header: "User Email", columnName: "user_email", canSort: false),
       grid.Column(header: "Role", columnName: "role"),

       grid.Column(header: "",format:(item) =>
       {
           var link = Html.ActionLink("Add New", "AddNew", "Admin", new { id = item.id }, htmlAttributes: new { @class = "btn btn-xs btn-vs" });
           return link;

       }),
       grid.Column(header: "", format: (item) =>
       {
           //var link = Html.ActionLink("Edit", "", "", new { id = item.id }, htmlAttributes: new { @class = "btn btn-xs btn-primary", onclick = "Modalshow()" });
           var link = Html.ActionLink("Edit", "Edit", "Admin", new { id = item.id }, htmlAttributes: new { @class = "btn btn-xs btn-primary" });
           return link;

       }),
       grid.Column(header: "", format: (item) =>
       {
           var link = Html.ActionLink("Delete", "Delete", "Admin", new { id = item.id }, htmlAttributes: new { @class = "btn btn-xs btn-danger", onclick = "return confirm('Are you sure you want to delete this item?');" });
           return link;

       }),
       grid.Column(header: "", format: (item) =>
       {
           var link = Html.ActionLink("Details", "Select", "Admin", new { id = item.id }, htmlAttributes: new { @class = "btn btn-xs btn-success " });
           return link;

       })

       )
        , htmlAttributes: new { @class = "table table-hover text-center" },
        nextText: "Go Next",
        previousText: "Go Back",
        footerStyle: ""
        )

在下面的部分中

grid.Column(header: "",format:(item) =>
       {
           var link = Html.ActionLink("Add New", "AddNew", "Admin", new { id = item.id }, htmlAttributes: new { @class = "btn btn-xs btn-vs" });
           return link;

如何将 user_email 作为参数传递来代替 item.id ? }),

【问题讨论】:

    标签: c# asp.net-mvc asp.net-mvc-5


    【解决方案1】:

    您可以在 id 的同时添加另一个参数

    试试下面的代码

     var link = Html.ActionLink("Add New", "AddNew", "Admin", new { id = item.id, user_email = "UserEmail" }, htmlAttributes: new { @class = "btn btn-xs btn-vs" });
    

    谢谢

    【讨论】:

    • 不,它的 null 。从您认为它将在 UserEmail 中设置一些值的位置??
    • 你必须传递的值
    • 您希望从哪里获得价值?它必须是来自同一行的电子邮件 ID。有什么建议吗?
    • 您的 WebGrid 被绑定到“模型”,因此“item.id”指的是模型上名为“id”的属性。如果您想按照此处的建议进行操作,您将需要模型上的一个名为 UserEmail 的属性。然后你可以说 user_email = item.UserEmail
    猜你喜欢
    • 2018-01-05
    • 2019-09-26
    • 2011-10-05
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多