我試着輸入一些數據到一個名爲「Cost」的ViewData
。這是從數據庫中的「PrinterCreditsCost」列取值,並顯示該列的值。但是,列名也顯示爲大括號,與僅顯示「2」相反,它顯示「{PrinterCreditCost = 2}」。有誰知道我該如何才能使它只顯示「2」。這是要在一個數學公式中使用,所以我只需要2ViewData顯示數據庫列名稱
的代碼如下:
傑森var result = (from a in db.tblOptions.Include(t => t.PrinterCreditCost)
where a.ID == 1
select new
{
a.PrinterCreditCost
}
).First();
ViewData["Cost"] = result;
更新:
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; }
嘗試添加.Value並給出了類似的結果。 「PrinterCreditCost = 2」而不是「Value = 2」 –
您可以發佈「PrinterCreditCost」類的代碼嗎? –
我會用它更新問題。對於這個特定的控制器來說,它是完全多餘的,因爲它是值得的。該表涉及到很多其他表格等。 –