Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
4.67/5 (2 votes)
See more:
var grid = new WebGrid(Model, rowsPerPage: 10, canPage: true, canSort: true);
XML
@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

VB
grid.Column("CompanyName",style: "col1", format: (item)=>  @<text>@Html.TextBoxFor("item", (String)item.CompanyName)


Can anyone spot what I am doing wrong?
Posted

1 solution

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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900