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
2010-05-10 07:36:00
+3
A:
public ActionResult Index()
{
// ...
return File(bytes, contentType);
}
PanJanek
2010-05-10 07:40:08
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.
2010-05-10 07:47:00
bah, you posted while i was writing.. :) +1
Flexo
2010-05-10 07:47:59
+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
2010-05-10 07:47:27