简体   繁体   English

'tostring'方法ASP.NET MVC没有重载

[英]no overload for the 'tostring' method ASP.NET MVC

I have this code and I am giving this error in which I can not solve. 我有此代码,并且给出了我无法解决的错误。

code: 码:

  public ActionResult GetData()
    {
        DateTime data = context.Reserva.Select(x => x.DataEntrada).ToString("MMMM");
        int ID = context.Reserva.Select(x => x.ID_Cliente).Count();
        Reserva obj = new Reserva();
        obj.DataEntrada = data;
        obj.ID_Cliente = ID;
        return Json(obj, JsonRequestBehavior.AllowGet);
    }

here: DateTime data = context.Reserva.Select(x => x.DataEntrada).ToString("MMMM"); 此处:DateTime数据= context.Reserva.Select(x => x.DataEntrada).ToString(“ MMMM”);

When running the code, I get this error: 运行代码时,出现此错误:

no overload for the 'toString' method

Model 模型

namespace WebApplication.Models.BaseDados
{
    using System;
    using System.Collections.Generic;

    public partial class Reserva
    {
        public int ID_Reserva { get; set; }
        public int ID_Cliente { get; set; }
        public System.DateTime DataEntrada { get; set; }
        public Nullable<System.DateTime> DataSaida { get; set; }
        public string TipoQuarto { get; set; }
        public int NumeroQuarto { get; set; }
        public Nullable<int> NumeroNoites { get; set; }
        public Nullable<decimal> Preço { get; set; }
        public string Observaçoes { get; set; }

        public virtual Cliente Cliente { get; set; }
    }
}

Assuming context.Reserva is indeed Reserva type. 假设context.Reserva确实是Reserva类型。 You don't even need Select , so just access the DataEntrada property directly. 您甚至不需要Select ,所以直接访问DataEntrada属性。 DataEntrada is type of DateTime , so you don't convert it ToString DataEntradaDateTime类型,因此您无需将其转换为ToString

DateTime data = context.Reserva.DataEntrada;

Also (not related to your question) as the follow up, the line after that is also wrong. 另外(与您的问题无关)作为后续措施,此后的一行也是错误的。

int ID = context.Reserva.ID_Cliente;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM