tags:

views:

65

answers:

3

Is it possible to return a string from controller upon a form submission ?

+6  A: 
[HttpPost]
public ActionResult Index()
{
    return Content("some string", "text/plain");
}
Darin Dimitrov
+3  A: 
public ActionResult Index()
{
    // ...
    return File(bytes, contentType);
}
PanJanek
Thanks, I have posted nearly same question on http://stackoverflow.com/questions/2800956/how-to-return-back-a-message-after-a-submit. Could you please refer to that to help me.
bah, you posted while i was writing.. :) +1
Flexo
+3  A: 

You can, as Darin suggest, return Content(string); There are also other possibilities such as

[HttpPost]
public ActionResult Index(FormCollection form) {
    /*
      return Json(json);
      return View;
      return PartialView;
    */
}

If you return something other than an action result it will automatically be wrapped in a ContentResult.

[HttpPost]
public ContentResult Index(FormCollection form) {
    /*
      return Content(string); 
      return File(bytes, contentType);
      return DateTime.Now;
      return 2;
    */
}
Flexo