Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type
Source Error:
Line 33: grid.Column("Cost", "LP",@<text>@String.Format("£{0:0.00}", item.Cost ?? 0)</text>) ,
Line 34: grid.Column("DiscountPrice", "DP", @<text>@String.Format("£{0:0.00}", item.DiscountPrice ?? 0)</text>),
Line 35: grid.Column("SRP", @<text>@String.Format("£{0:0.00}", item.SRP ?? 0)</text>)
Line 36: /* grid.Column("CatID", "ID")*/
Line 37: )
SRP is a calculation (and is a money data type) I want to covert the 4 leading decimal places to 2 decimal places. Please help. Thanks.
Since you have missed the second parameter out (the header parameter) you need to specify the name of subsequent parameters that you are providing values for. In this case, you need to specify the
format parameter, otherwise your Func<object, HelperResult> will be mistaken for a string (which is what the header parameter accepts):
Hi, Thanks for the answer, much appreciated. I have used this method for another grid but get an error on this code:
@{
var db = Database.Open("A-LensCatFE-01SQL") ;
var CustomerCode = UrlData[0];
var query1 = ("Select CatID from dbo.qryCustomersAll Where CustomerCode= @0");
var catid = db.QueryValue(query1, CustomerCode);
var query2 = ("Select * from dbo.qryAppFactsTotsXtab Where CustomerCode= @0 AND CatID=@1 Order by LensForm, LensCode");
var data2 = db.Query(query2, CustomerCode, catid);
var columns2 = new[]{"LensCode", "HC-UNC", "AR-HC", "AR-HMC+", "AR-LET", "AR-OS", "AR-UNC", "SC", "GT","Oth-Occ"};
var grid2 = new WebGrid(data2, ajaxUpdateContainerId : "grid2");
}
<h3>+ Options SRP</h3>
@grid2.GetHtml(
tableStyle: "table",
headerStyle: "header",
footerStyle:"footer",
alternatingRowStyle: "alternate",
columns: grid2.Columns(
grid2.Column("LensCode","Code"),
grid2.Column("HC-UNC", format: @<text>@String.Format("£{0:0.00}", item.HC-UNC ?? 0)</text>),
grid2.Column("AR-HC", format: @<text>@String.Format("£{0:0.00}", item.AR-HC ?? 0)</text>),
grid2.Column("AR-HMC+", format: @<text>@String.Format("£{0:0.00}", item.AR-HMC+ ?? 0)</text>),
grid2.Column("AR-LET", format: @<text>@String.Format("£{0:0.00}", item.AR-LET ?? 0)</text>) ,
grid2.Column("AR-OS", format: @<text>@String.Format("£{0:0.00}", item.AR-OS ?? 0)</text>),
grid2.Column("AR-UNC", format: @<text>@String.Format("£{0:0.00}", item.AR-UNC ?? 0)</text>),
grid2.Column("SC", format: @<text>@String.Format("£{0:0.00}", item.SC ?? 0)</text>),
grid2.Column("GT", format: @<text>@String.Format("£{0:0.00}", item.GT ?? 0)</text>),
grid2.Column("Oth-Occ", format: @<text>@String.Format("£{0:0.00}", item.Oth-Occ ?? 0)</text>)
)
)
The error report is:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1525: Invalid expression term '??'
Source Error:
Line 26: grid2.Column("HC-UNC", format: @<text>@String.Format("£{0:0.00}", item.HC-UNC ?? 0)</text>),
Line 27: grid2.Column("AR-HC", format: @<text>@String.Format("£{0:0.00}", item.AR-HC ?? 0)</text>),
Line 28: grid2.Column("AR-HMC+", format: @<text>@String.Format("£{0:0.00}", item.AR-HMC+ ?? 0)</text>),
Line 29: grid2.Column("AR-LET", format: @<text>@String.Format("£{0:0.00}", item.AR-LET ?? 0)</text>) ,
Line 30: grid2.Column("AR-OS", format: @<text>@String.Format("£{0:0.00}", item.AR-OS ?? 0)</text>),
Source File: c:\Users\vijlebbo\Documents\My Web Sites\LensCatalogueSystem\GridOptions.cshtml Line: 28
It seems the formating does not like hypenated names or names with + signs in them. How can I rid of this error?
Or do you think I should bite the bullet and rename these columns?
Member
52 Points
252 Posts
Lambda error?
May 08, 2013 10:48 AM|Liquidmetal|LINK
Hi, aargh yes another issue!
I have this code:
The above is returning an error:
SRP is a calculation (and is a money data type) I want to covert the 4 leading decimal places to 2 decimal places. Please help. Thanks.
All-Star
194004 Points
28027 Posts
Moderator
Re: Lambda error?
May 08, 2013 12:29 PM|Mikesdotnetting|LINK
Since you have missed the second parameter out (the header parameter) you need to specify the name of subsequent parameters that you are providing values for. In this case, you need to specify the format parameter, otherwise your Func<object, HelperResult> will be mistaken for a string (which is what the header parameter accepts):
Member
52 Points
252 Posts
Re: Lambda error?
May 09, 2013 06:15 AM|Liquidmetal|LINK
Hi, Thanks for the answer, much appreciated. I have used this method for another grid but get an error on this code:
The error report is:
It seems the formating does not like hypenated names or names with + signs in them. How can I rid of this error?
Or do you think I should bite the bullet and rename these columns?
Once again thanks.
Member
52 Points
252 Posts
Re: Lambda error?
May 09, 2013 07:22 AM|Liquidmetal|LINK
I have bitten the bullet and removed the hyphens and + in the column names and now the formating code does work.
My tables are now populated with the relevant data with the £ sign and to decimal places.
Thanks to Mike for all your help.