Razor Page - An error occurred during the compilation of a resource

I am getting the following error when I try to execute an sql server stored procedure

Error

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

C:\\inetpub\\wwwroot\\staging_publishing\\zia_ReconIQ\\Views\\Home\\ExecuteBankReconMatchingsp.cshtml

* ### The name 'EntityID' does not exist in the current context
* ### The name 'GLAccount' does not exist in the current context
* ### The name 'ReconYear' does not exist in the current context
* ### The name 'ReconMonth' does not exist in the current context

Below is my step by step process

Custom View Tag from generated table

<a href="ExecuteBankReconMatchingsp?entityId=@UrlEncode(CurrentPage.EntityID?.CurrentValue ?? "")&postingMonth=@UrlEncode(CurrentPage.ReconMonth?.CurrentValue ?? "")&postingYear=@UrlEncode(CurrentPage.ReconYear?.CurrentValue ?? "")&glAccountNumber=@UrlEncode(CurrentPage.GLAccount?.CurrentValue ?? "")">

Execute Matching

Content of Custom File : ExecuteBankReconMatchingsp

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Data;
using System.Data.SqlClient;

public class ExecuteBankReconMatchingspModel : PageModel
{
    private readonly IConfiguration _config;

    public ExecuteBankReconMatchingspModel(IConfiguration config)
    {
        _config = config;
    }

    [BindProperty(SupportsGet = true)]
    public string EntityID { get; set; }

    [BindProperty(SupportsGet = true)]
    public string GLAccount { get; set; }

    [BindProperty(SupportsGet = true)]
    public int ReconYear { get; set; }

    [BindProperty(SupportsGet = true)]
    public int ReconMonth { get; set; }

    public async Task<IActionResult> OnGetAsync()
    {
        var result = new Dictionary<string, string>();

        using var conn = new SqlConnection(_config.GetConnectionString("DefaultConnection"));
        using var cmd = new SqlCommand("SP_MLCockpitStaging", conn)
        {
            CommandType = CommandType.StoredProcedure
        };

        cmd.Parameters.AddWithValue("@EntityID", EntityID);
        cmd.Parameters.AddWithValue("@GLAccount", GLAccount);
        cmd.Parameters.AddWithValue("@ReconYear", ReconYear);
        cmd.Parameters.AddWithValue("@ReconMonth", ReconMonth);

        await conn.OpenAsync();
        using var reader = await cmd.ExecuteReaderAsync();

        if (await reader.ReadAsync())
        {
            result["entityId"] = reader["EntityID"]?.ToString() ?? "";
            result["postingMonth"] = reader["PostingMonth"]?.ToString() ?? "";
            result["postingYear"] = reader["PostingYear"]?.ToString() ?? "";
            result["glAccountNumber"] = reader["GLAccountNumber"]?.ToString() ?? "";
            result["totalRecords"] = reader["TotalRecordsProcessed"]?.ToString() ?? "";
            result["matched"] = reader["MatchedRecords"]?.ToString() ?? "";
            result["unmatchedBank"] = reader["UnmatchedBankRecords"]?.ToString() ?? "";
            result["unmatchedLedger"] = reader["UnmatchedLedgerRecords"]?.ToString() ?? "";
            result["processingTime"] = reader["ProcessingTime"]?.ToString() ?? "";
            result["runTimestamp"] = reader["RunTimestamp"]?.ToString() ?? "";
        }

        return RedirectToPage("matchingenginesuccess", result);
    }
}

Would really appreciate a non expert level guidance as I am not a developer. I am a business analyst using ASP.NET Maker for our business needs

It should be easier to create an API action to execute your stored procedure.

I updated my custom page as follows to use API action and get the following error

ERROR

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

C:\inetpub\wwwroot\staging_publishing\zia_ReconIQ\Views\Home\ExecuteBankReconMatchingsp.cshtml

  • The name 'EntityID' does not exist in the current context
  • The name 'GLAccount' does not exist in the current context
  • The name 'ReconYear' does not exist in the current context
  • The name 'ReconMonth' does not exist in the current context

UPDATED CODE

public void Route_Action(IEndpointRouteBuilder app)
{
    app.MapGet(
        "/api/RunBankRecon/{entityId}/{glAccount}/{reconYear:int}/{reconMonth:int}",
        async (string entityId, string glAccount, int reconYear, int reconMonth, IConfiguration config) =>
        {
            var result = new Dictionary<string, string>();

            using var conn = new SqlConnection(config.GetConnectionString("DefaultConnection"));
            using var cmd = new SqlCommand("SP_MLCockpitStaging", conn)
            {
                CommandType = CommandType.StoredProcedure
            };

            cmd.Parameters.AddWithValue("@EntityID", entityId);
            cmd.Parameters.AddWithValue("@GLAccount", glAccount);
            cmd.Parameters.AddWithValue("@ReconYear", reconYear);
            cmd.Parameters.AddWithValue("@ReconMonth", reconMonth);

            await conn.OpenAsync();
            using var reader = await cmd.ExecuteReaderAsync();

            if (await reader.ReadAsync())
            {
                result["entityId"]          = reader["EntityID"].ToString();
                result["postingMonth"]      = reader["PostingMonth"].ToString();
                result["postingYear"]       = reader["PostingYear"].ToString();
                result["glAccountNumber"]   = reader["GLAccountNumber"].ToString();
                result["totalRecords"]      = reader["TotalRecordsProcessed"].ToString();
                result["matched"]           = reader["MatchedRecords"].ToString();
                result["unmatchedBank"]     = reader["UnmatchedBankRecords"].ToString();
                result["unmatchedLedger"]   = reader["UnmatchedLedgerRecords"].ToString();
                result["processingTime"]    = reader["ProcessingTime"].ToString();
                result["runTimestamp"]      = reader["RunTimestamp"].ToString();
            }

            var query = string.Join("&",
                result.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}"));

            var redirectUrl = $"/matchingenginesuccess?{query}";
            return Results.Redirect(redirectUrl);
        }
    );
}

This is the custom view tag that is calling the page

<a href="ExecuteBankReconMatchingsp?entityId=@UrlEncode(CurrentPage.EntityID?.CurrentValue ?? "")&postingMonth=@UrlEncode(CurrentPage.ReconMonth?.CurrentValue ?? "")&postingYear=@UrlEncode(CurrentPage.ReconYear?.CurrentValue ?? "")&glAccountNumber=@UrlEncode(CurrentPage.GLAccount?.CurrentValue ?? "")">
Execute Matching

Route_Action is not to be placed in Custom File, you should use Route_Action server event and remove your Custom File.

And you don’t need to connect again yourself. If your "DefaultConnection"is the main database in the project, you may try:

        var result = await Conn.QueryFirstOrDefaultAsync<Dictionary<string, object>>(
            "SP_MLCockpitStaging",
            new
            {
                EntityID = entityId,
                GLAccount = glAccount,
                ReconYear = reconYear,
                ReconMonth = reconMonth
            },
            commandType: CommandType.StoredProcedure
        );

The resultis Dictionary<string, object>.

Apologies if my question is elementary?

How does my custom view tag call the route action and pass the following values from my record (EntityID, GLAccount, ReconYear and ReconMonth) as variables to the stored procedure SP_MLCockpitStaging

var result = await Conn.QueryFirstOrDefaultAsync<Dictionary<string, object>>(
            "SP_MLCockpitStaging",
            new
            {
                EntityID = entityId,
                GLAccount = glAccount,
                ReconYear = reconYear,
                ReconMonth = reconMonth
            },
            commandType: CommandType.StoredProcedure
        );

Just pass as the route parameters