gpt4 book ai didi

c# - 在 WebGrid.column 内的 HTML.ActionLink 中使用数据,不可能吗?

转载 作者:IT王子 更新时间:2023-10-29 04:42:21 24 4
gpt4 key购买 nike

我的 ASP.NET MVC3 测试应用程序中有以下 WebGrid。它显示客户列表:

@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns
(
grid.Column(format: (item) => Html.ActionLink("Edit", "Details", new { id = item.id })),
grid.Column("Address.CompanyName"),
grid.Column("Address.City")
)
)

这里有趣的部分是我在第一列中添加的编辑链接。我想使用客户帐号而不是普通的“编辑”测试。然而,这样做给我带来了很多问题。

我试过:

grid.Column(format: (item) => Html.ActionLink(item.AccountNumber.ToString(), "Details", new { id = item.id })),

但是,似乎我不明白这是如何工作的,因为我一直收到这个异常:

CS1502: The best overloaded method match for 'System.Web.Helpers.WebGrid.Column(string, string, System.Func<dynamic,object>, string, bool)' has some invalid arguments

谁能向我解释为什么这不起作用? “编辑”和 item.AccountNumber.ToString() 之间有什么区别(拼写除外)?

我应该注意,当使用“编辑”文本时链接有效,并且 AccountNumber 很长。

最佳答案

这是我如何处理日期的示例。

grid.Column(columnName: "Date", format: (item) => Html.ActionLink(((string)item.Date), "Edit", new { id = item.id })),          

You have to beware of using extension methods (Html.*) with dynamics (item)... it doesn't work well in csharp. When you do the new {} projection or call ToString, it's no longer dynamic. Alternatively, you could cast: (object)item.Id.

来自 here .

关于c# - 在 WebGrid.column 内的 HTML.ActionLink 中使用数据,不可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6167903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com