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?
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?
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 ==========
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);
}