locked
Lambda error? RRS feed

  • Question

  • User743508062 posted

    Hi, aargh yes another issue!

    I have 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.qryDiscountLensPrice Where CustomerCode= @0 AND CatID=@1 Order by LensForm, LensCode");
       var data2 = db.Query(query2, CustomerCode, catid);
    
       var columns2 = new[]{"LensCode", "ShortName", "Description", "Index", "Cost", "DiscountPrice", "SRP", /*"CatID"*/};
    
       var grid = new WebGrid(data2, ajaxUpdateContainerId : "grid");
    }
     
    <h3>Lens SRP</h3> 
    @grid.GetHtml(
        tableStyle: "table", 
        headerStyle: "header", 
        footerStyle:"footer",
        alternatingRowStyle: "alternate",
        columns: grid.Columns(
                    grid.Column("LensCode","Code"),
                    grid.Column("ShortName","LF"),
                    grid.Column("Description","Product"),
                    grid.Column("Index"),
                    grid.Column("Cost", "LP",@<text>@String.Format("£{0:0.00}", item.Cost ?? 0)</text>) ,
                    grid.Column("DiscountPrice", "DP", @<text>@String.Format("£{0:0.00}", item.DiscountPrice ?? 0)</text>),
                    grid.Column("SRP", @<text>@String.Format("£{0:0.00}", item.SRP ?? 0)</text>)
                  /*  grid.Column("CatID", "ID")*/
                   )
            )
    grid.Column("SRP", @<text>@String.Format("£{0:0.00}", item.SRP ?? 0)</text>)
    

    The above is returning an error:

    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.


    Wednesday, May 8, 2013 10:48 AM

Answers

  • User-821857111 posted

    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):

    grid.Column("SRP", format: @<text>@String.Format("£{0:0.00}", item.SRP ?? 0)</text>)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 8, 2013 12:29 PM

All replies

  • User-821857111 posted

    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):

    grid.Column("SRP", format: @<text>@String.Format("£{0:0.00}", item.SRP ?? 0)</text>)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 8, 2013 12:29 PM
  • User743508062 posted

    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?

    Once again thanks.

     



    Thursday, May 9, 2013 6:15 AM
  • User743508062 posted

    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. 

    Thursday, May 9, 2013 7:22 AM