开发者

Is it possible to return anything else from controller apart from view?

Is it possible to return a string from controller upon a form s开发者_运维问答ubmission ?


[HttpPost]
public ActionResult Index()
{
    return Content("some string", "text/plain");
}


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;
    */
}


public ActionResult Index()
{
    // ...
    return File(bytes, contentType);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜