ASP.NET MVC2 Checkboxes in a table

拈花ヽ惹草 提交于 2019-12-13 05:45:48

问题


I'm currently trying to create a view in asp.net MVC2 which includes a checkbox in each row. This will be a "mark" box, and there will be a button on the view which can then be used for multiple deletion.

I have a model which contains a list of the objects being listed, so I have some code which reads as:-

<% foreach (CancelledCard item in Model.CancelledCards) { %>

I've then tried to use

<%: Html.CheckBoxFor(item >= item.Checked) %>

but I'm getting an error.

What am I missing? What's the right way to do this in MVC2?


回答1:


In C# a lambda expression uses => and not >=:

<%: Html.CheckBoxFor(item => item.Checked) %>

Also instead of saying that you get an error, you could have posted the error message. It would have been much more clear.




回答2:


<%: Html.CheckBoxFor(item >= item.Checked) %>

is wrong. It should be:

<%: Html.CheckBoxFor(item => item.Checked) %>


来源:https://stackoverflow.com/questions/3966823/asp-net-mvc2-checkboxes-in-a-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!