public ActionResult TestNullAction()
{
return null;
}
/// <summary>
/// 查看HTML原文件显示:您好!
/// </summary>
public void TestVoidAction()
{
Response.ContentType = "text/plain";
Response.Write("您好!");
}
/// <summary>
/// 查看HTML原文件显示:测试ContentResult
/// </summary>
/// <returns></returns>
public ContentResult TestContentResult()
{
return Content("测试ContentResult");
}
/// <summary>
/// 显示一个图片文件
/// </summary>
/// <returns></returns>
public ActionResult FileContentResultDemo()
{
FileStream fs = new FileStream(Server.MapPath(@"/Content/Images/1335230.jpg"), FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[Convert.ToInt32(fs.Length)];
fs.Read(buffer, 0, Convert.ToInt32(fs.Length));
return File(buffer, @"image/gif");
}
/// <summary>
/// 显示一个下载框
/// </summary>
/// <param name="fileId"></param>
/// <returns></returns>
public ActionResult FilePathResultDemo(int fileId)
{
//可以将一个jpg格式的图像输出为gif格式
string filePath = "/Content/Images/error.png";
return File(Server.MapPath(filePath), "text/plain", Path.GetFileName(filePath));
}
/// <summary>
/// 抛出一个无权限结果,context.HttpContext.Response.StatusCode = 401;
/// </summary>
/// <returns></returns>
public ActionResult HttpUnauthorizedResultDemo()
{
return new HttpUnauthorizedResult();
}
/// <summary>
/// 返回一个名为“JavaScriptResultDemo”的JS文件,文件中的内容为:alert("Hello World!");
/// </summary>
/// <returns></returns>
public ActionResult JavaScriptResultDemo()
{
return JavaScript("alert(\"Hello World!\");");
}
public ActionResult JsonResultDemo()
{
var tempObj = new { Controller = "DemoController", Action = "JsonResultDemo" };
return Json(tempObj,"text/plain",Encoding.UTF8,JsonRequestBehavior.AllowGet);
}
public ActionResult RedirectResultDemo()
{
return Redirect("http://www.baidu.com");
}
public EmptyResult TestEmptyResult()
{
return new EmptyResult();
}
public ActionResult TestAjaxHelper()
{
return View();
}
public HttpUnauthorizedResult TestHttpUnauthorizedResult()
{
return null;
}