Cast error int ActionResult

1

I'm using VS 2017 for a tutorial but I get the error: You can not implicitly convert the long type to System.Web.MVC.ActionResult

How do you fix that?

The controller

 public class DefaultController : Controller
{
    private TablaDato tabladato = new TablaDato();
    // GET: Default
    public ActionResult Index()
    {
        return Convert.ToInt64(tabladato.Conteo());
    }
}

TablaDato.cs

  [Table("TablaDato")]
    public partial class TablaDato
    {
        [Key]
        [Column(Order = 0)]
        [StringLength(20)]
        public string Relacion { get; set; }

        [Key]
        [Column(Order = 1)]
        [StringLength(20)]
        public string Valor { get; set; }

        [Required]
        [StringLength(50)]
        public string Descripcion { get; set; }

        public int Orden { get; set; }

        public int Conteo() {
            using (var ctx = new contextoProyectoPortafolio())
            {
                return ctx.TablaDato.Count();
            }

        }
    
asked by Jhon Hernández 08.09.2018 в 05:31
source

1 answer

0

The error is because in your controller you return a data type Int64 when you should return a ActionResult . To correct the problem you must return a View with the result of your data:

public class DefaultController : Controller
{
    private TablaDato tabladato = new TablaDato();
    // GET: Default
    public ActionResult Index()
    {
        return View(Convert.ToInt64(tabladato.Conteo()));
    }
}

Or, where appropriate, a json , everything depends on what you expect in the view:

public class DefaultController : Controller
{
    private TablaDato tabladato = new TablaDato();
    // GET: Default
    public ActionResult Index()
    {
        return Json(Convert.ToInt64(tabladato.Conteo()), JsonRequestBehavior.AllowGet);
    }
}
    
answered by 08.09.2018 в 05:49