0

I got a error (CS0103 C# The name 'Content' does not exist in the current context) in code below:

public ActionResult getsomething()
{
    var res = "something";
    return Content(res);}

Do u have any idea i can fix that?

Anamnian
  • 405
  • 3
  • 18

2 Answers2

1

Try use System.Web.Mvc.Controller Content() function instead System.Web.UI.WebControls.Content Class

EDIT:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication2.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return Content("xxxxx");
        }
    }
}

Its work fine
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Narek Arzumanyan
  • 616
  • 3
  • 11
0

Edit: My bad, not used to ASP.NET. Will keep my previous answer for transparency

Seeing this answer here, use ContentResult instead of ActionResult

public ContentResult getsomething()
{
    var res = "something";
    return Content(res);
}

Original post:

Did you try adding the new keyword ? Content is a class, thus need to be initialized.

public ActionResult getsomething()
{
    var res = "something";
    return new Content(res);
}
Community
  • 1
  • 1
Etienne Faucher
  • 2,561
  • 1
  • 17
  • 21