如何使用html助手格式化网格列 [英] how to format web grid columns with html helpers
本文介绍了如何使用html助手格式化网格列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var grid = new WebGrid(Model,rowsPerPage:10,canPage:true,canSort:true);
@ grid.GetHtml(
列:new []
{
grid.Column(CompanyId,
style:col7,
格式:@ < p >
< 输入 type = text < span class =code-attribute> id = HCompanyId value = @ item.CompanyId / >
< / p > ),
grid。列(CompanyName,
样式:col1,
格式:(@ item)=> Html.TextBoxFor(item.CompanyName)),
grid.Column (CompanyUrl,
样式:col2,
格式:@ < text > < span id = companyurl class = display-mode > @ item.CompanyUrl < / span >
< 输入 type = text id = txtUrl value = @ item.CompanyUrl class = 编辑模式 / >
< / text > ),
grid.Column(,标题:操作,
样式:col4,
格式:@ < p >
< ; 输入 type < span class =code-keyword> = button id = btnEdit value = 编辑 c lass = editdisplay-mode / >
< 输入 type = 按钮 id = btnSave value = 保存 class = Saveedit-mode / >
< / p > ),
},
headerStyle:webgridHeader ,
tableStyle:webgrid,
模式:WebGridPagerModes.All,
footerStyle:webgridFooter,
htmlAttributes:new {id =grdCompanies})
webgrid的CompanyName列显示错误无法将lamdaexpression转换为sysstem.function动态对象
在这个正常的html控件工作正常但是html助手不能正常工作。
我试过
grid.Column( CompanyName,style: col1,格式:(ite米)=> @< text> @ Html.TextBoxFor( item,(字符串)item.CompanyName)
有人能看出我做错了吗?
解决方案
你正在使用@ Html.TextBoxFor的错误重载。
尝试使用这样的
grid.Column(CompanyName ,style:col1,格式:( item)=> @< text> @ Html.TextBox(item,(String)item.CompanyName)< / text>
var grid = new WebGrid(Model, rowsPerPage: 10, canPage: true, canSort: true);
@grid.GetHtml(
columns: new[]
{
grid.Column("CompanyId",
style:"col7",
format:@<p>
<input type="text" id="HCompanyId" value="@item.CompanyId" />
</p>),
grid.Column("CompanyName",
style: "col1",
format:(@item)=>Html.TextBoxFor(item.CompanyName)),
grid.Column("CompanyUrl",
style: "col2",
format: @<text> <span id="companyurl" class="display-mode">@item.CompanyUrl</span>
<input type="text" id="txtUrl" value="@item.CompanyUrl" class="edit-mode"/>
</text>),
grid.Column("",header:"Actions",
style: "col4",
format:@<p>
<input type="button" id="btnEdit" value="Edit" class="editdisplay-mode" />
<input type="button" id="btnSave" value="Save" class="Saveedit-mode" />
</p>),
},
headerStyle: "webgridHeader",
tableStyle: "webgrid",
mode: WebGridPagerModes.All,
footerStyle: "webgridFooter",
htmlAttributes: new { id = "grdCompanies" })
CompanyName column of webgrid showing error "cannot convert lamdaexpression to sysstem.function dynamic object"
In this normal html controls are working fine but html helpers are not working.
I tried
grid.Column("CompanyName",style: "col1", format: (item)=> @<text>@Html.TextBoxFor("item", (String)item.CompanyName)
Can anyone spot what I am doing wrong?
解决方案
You are using wrong overload of @Html.TextBoxFor.
Try using like this
grid.Column("CompanyName",style: "col1", format: (item)=> @<text>@Html.TextBox("item", (String)item.CompanyName)</text>
这篇关于如何使用html助手格式化网格列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文