MVC 3 texbox中的WebGrid(剃刀) [英] Mvc 3 texbox in webgrid (razor)
问题描述
简单的问:你怎么我得到的文本框显示的值。 code以下无法在item.LastName
@model名单< Mvc2010_11_12.Models.Employee>
@ {
VAR电网=新的WebGrid(来源:型号,defaultSort:名字,rowsPerPage:3);
}< DIV ID =GRID1>
@ grid.GetHtml(列:grid.Columns(
grid.Column(姓氏),
grid.Column(格式:(项目)=> Html.TextBox(姓氏,item.LastName))
))
< / DIV>
扩展方法(即Html.TextBox)不能很好地与动态对象(即项目)......这是C#的限制。工作
您已经有了几个选择:
格式:InputExtensions.TextBox(HTML,姓,item.LastName)//静态调用
格式:Html.TextBox(姓,(对象)item.LastName)//投非动态对象
格式:LT;输入类型=文本名称=姓氏值=@ item.LastName/> //避免扩展
另外,我相信有以项参数的内在拉姆达 - 你不应该需要这个宣布自己
。Simple Q:How do you I get the textbox to show the value. Code below fail on 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>
Extension methods (i.e., Html.TextBox) don't work well with dynamic objects (i.e., item)... it's a limitation of c#.
You've got a few options:
format: InputExtensions.TextBox(Html, "Last Name", item.LastName) // static call
format: Html.TextBox("Last Name", (object)item.LastName) // cast as non-dynamic object
format: <input type="text" name="LastName" value="@item.LastName" /> // avoid extensions
Also, I believe there's an inherent lambda with an "item" parameter - you shouldn't need to declare this yourself.
这篇关于MVC 3 texbox中的WebGrid(剃刀)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!