Using data in a HTML.ActionLink inside a WebGrid.c

2020-02-03 05:26发布

I have the following WebGrid in my ASP.NET MVC3 test application. It displays a list of customers:

@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")
         )
)

The interesting part here is the Edit-link I've added in the first column. I would like to use the customers account number instead of the plain "Edit"-test. However, it causes me a great deal of problems to do so.

I've tried:

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

However, it seems like there is something i don't understand about how this works because i keep getting this exception:

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

Can anyone explain to me why this isn't working? What is the difference between "Edit" and item.AccountNumber.ToString() (apart from the spelling)?

I should note that the link works when using the "Edit"-text, and that AccountNumber is a long.

8条回答
该账号已被封号
2楼-- · 2020-02-03 06:27

In my case Derek Beattie solution is not working.

And I use this

 grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.ID }), style: "column-action") 
查看更多
Juvenile、少年°
3楼-- · 2020-02-03 06:31

I have solved like this

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

查看更多
登录 后发表回答