I've tried inputting some data into a ViewData
called "Cost". This is taking a value from the "PrinterCreditsCost" column in a database, and should display the value of that column. However, the Column name is also displayed with curly brackets, so as opposed to just display "2" it displays "{ PrinterCreditCost = 2 }". Does anyone know how can I have it so that it only displays "2". This is going to be used in a mathematical equation, so I only need the 2.
The code is as follows:
var result = (from a in db.tblOptions.Include(t => t.PrinterCreditCost)
where a.ID == 1
select new
{
a.PrinterCreditCost
}
).First();
ViewData["Cost"] = result;
Update for Jason:
public int ID { get; set; }
public int Visible { get; set; }
public int DeleteLicense { get; set; }
public Nullable<int> ICTSurvey { get; set; }
public Nullable<int> PaidWorkSurvey { get; set; }
public Nullable<int> ICTGeneralSurvey { get; set; }
public Nullable<int> PESSCLSurvey { get; set; }
public Nullable<int> PastSurvey { get; set; }
public Nullable<int> PresentSurvey { get; set; }
public Nullable<int> Yr11Survey { get; set; }
public Nullable<int> NewScientistCount { get; set; }
public Nullable<int> UCASYear { get; set; }
public Nullable<int> OnlineSurveyActive { get; set; }
public Nullable<int> OnlineExaminationsActive { get; set; }
public string UCASFirstHalf { get; set; }
public string UCASSecondHalf { get; set; }
public string SIMSManual { get; set; }
public string SIMSApplication { get; set; }
public string SIMSAmpark { get; set; }
public Nullable<double> PrinterCreditFund { get; set; }
public Nullable<int> PrinterCreditCost { get; set; }
public string UCASIndividualFirstHalf { get; set; }
public string UCASIndividualSecondHalf { get; set; }
public string BookingSheetYear { get; set; }
public Nullable<System.DateTime> InductionDate { get; set; }
public string InductionYear { get; set; }
public virtual ICollection<tblPrinterCredit> tblPrinterCredits { get; set; }
In this bit of the query
select new
{
a.PrinterCreditCost
}
is there a property of PrinterCreditCost
you need to use e.g.
select new
{
a.PrinterCreditCost.Value
}
I don't know if Value
is the property you need, it might be called something else.
As it stands, it does indeed look like your query is returning the column definition, rather than the value of that column.
EDIT:
I see the following:
public Nullable<int> PrinterCreditCost { get; set; }
So I'm surprised that
select new
{
a.PrinterCreditCost.Value
}
Does not work. As it's a nullable value, the .Value
property should return the value, not { Value = 2 }
. I'm not sure what's going on there.