简单问:如何让文本框显示值. item.LastName上的代码失败
@model List<Mvc2010_11_12.Models.Employee> @{ var grid = new WebGrid(source: Model,defaultSort: "FirstName",rowsPerPage: 3); } <div id="grid1"> @grid.GetHtml(columns: grid.Columns( grid.Column("LastName"),grid.Column(format: (item) => Html.TextBox("LastName",item.LastName)) )) </div>
解决方法
扩展方法(即Html.TextBox)不适用于动态对象(即项目)……这是c#的限制.
你有几个选择:
format:InputExtensions.TextBox(Html,“Last Name”,item.LastName)//静态调用
格式:Html.TextBox(“Last Name”,(object)item.LastName)//强制转换为非动态对象
格式:& lt; input type =“text”name =“LastName”value =“@ item.LastName”/& gt; //避免扩展
另外,我相信有一个带有“item”参数的固有lambda – 你不应该自己声明这个.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。