Thursday 27 July 2017

Asp.Net Mvc: ContentResult vs. string

You can't return a string on a method which returns an ActionResult, so this is when you could use a ContentResult to return a plain string like so:
public ContentResult Hello()
{
    return Content("hello world!");
}
ContentResult by default returns a type of text/plain. If you only ever needed to return a string, then you would use the method to return a string

 public ActionResult Register()
        {

            return Content("<tt>sdfsf</tt>","text/xml");
        }

    public ActionResult Register()
        {

            return Content("dgdfg","text/json");
        }

 public ActionResult Register()
        {

            return Content("dgdfg","text/plan");
        }


No comments:

Post a Comment

Recent Post

Parallel Task in .Net 4.0