In my previous code, I try in the view. I think I will need to check first if the id is empty or null then set the value equal to 0 but I got an error, says, accessing local variable is not allow. But how can I access a local variable of var inside of if statement?
var Rs1;
if (id != null)
{
    Rs1 = _context.DwPropertyDetails.Select(x => new
    {
        Rs1Clm2 = totalTransAmount,
        Rs1Clm3 = x.Studio),
        Rs1Clm4 = x.OneBedroom),
        Rs1Clm5 = x.TwoBedroom),
        Rs1Clm6 = x.ThreeBedroom),
        Rs1Clm7 = x.Total),
    });
}
else
{
    Rs1 = _context.DwPropertyDetails.Select(x => new
    {
        Rs1Clm2 = 0,
        Rs1Clm3 = 0,
        Rs1Clm4 = 0,
        Rs1Clm5 = 0,
        Rs1Clm6 = 0,
        Rs1Clm7 = 0,
    });
}