ActionResult
public abstract class ActionResult
{
public abstract void ExecuteResult(ControllerContextcontext);
}
命令模式
容器对象
ActionResult的重载
-EmptyResult 没有任何匹配和执行
-ContentResult 输出纯文本 AJAX
-JsonResult
-RedirectResult
-RedirectToRouteResult
-ViewResult
-PartialViewResult
-FileResult -File操作 FilePathResult FileContentResult FileStreamResult
-FileContentResult
-FileStreamResult
-JavaScriptResult
JsonResult
public ActionResultPartialJson()
{
varcategory = new ProductCategory{ Name=”Partial”};
varresult = new {
Name = category.Name,
ProductCount= category.Products.Count};
return Json(result);
}
JavaScriptResult
public ActionResultDoSomething() {
script s = “$(‘#some-div’).html(‘Updated!’);”
;return JavaScript(s);
}
<%: Ajax.ActionLink(“click”, “DoSomething”, new AjaxOptions()) %>
<div id=”some-div”></div>
RedirectResult
自动跳转
RedirectToRouteResult
-RedirectToRoute
-RedirectToAction
ViewResult和PartialViewResult
使用字典类返回结果
Action Result Helper函数
输出结果帮助函数
方法 描述
Redirect
RedirectToAction
RedirectToRoute
View
PartialView
Content
File
Json
JavaScript
隐式调用Action Results
public double Distance(int x1, int y1, int x2, int y2)
{
double xSquared= Math.Pow(x2 -x1, 2);
double ySquared= Math.Pow(y2 -y1, 2);
return Math.Sqrt(xSquared+ ySquared);
}
public ActionResultDistance(intx1, inty1, intx2, inty2)
{
double xSquared= Math.Pow(x2 -x1, 2);
double ySquared= Math.Pow(y2 -y1, 2);
double distance = Math.Sqrt(xSquared+ ySquared);
return Content(distance.ToString(CultureInfo.InvariantCulture));
}
2011-4-17 16:16 danny
public abstract class ActionResult
{
public abstract void ExecuteResult(ControllerContextcontext);
}
命令模式
容器对象
ActionResult的重载
-EmptyResult 没有任何匹配和执行
-ContentResult 输出纯文本 AJAX
-JsonResult
-RedirectResult
-RedirectToRouteResult
-ViewResult
-PartialViewResult
-FileResult -File操作 FilePathResult FileContentResult FileStreamResult
-FileContentResult
-FileStreamResult
-JavaScriptResult
JsonResult
public ActionResultPartialJson()
{
varcategory = new ProductCategory{ Name=”Partial”};
varresult = new {
Name = category.Name,
ProductCount= category.Products.Count};
return Json(result);
}
JavaScriptResult
public ActionResultDoSomething() {
script s = “$(‘#some-div’).html(‘Updated!’);”
;return JavaScript(s);
}
<%: Ajax.ActionLink(“click”, “DoSomething”, new AjaxOptions()) %>
<div id=”some-div”></div>
RedirectResult
自动跳转
RedirectToRouteResult
-RedirectToRoute
-RedirectToAction
ViewResult和PartialViewResult
使用字典类返回结果
Action Result Helper函数
输出结果帮助函数
方法 描述
Redirect
RedirectToAction
RedirectToRoute
View
PartialView
Content
File
Json
JavaScript
隐式调用Action Results
public double Distance(int x1, int y1, int x2, int y2)
{
double xSquared= Math.Pow(x2 -x1, 2);
double ySquared= Math.Pow(y2 -y1, 2);
return Math.Sqrt(xSquared+ ySquared);
}
public ActionResultDistance(intx1, inty1, intx2, inty2)
{
double xSquared= Math.Pow(x2 -x1, 2);
double ySquared= Math.Pow(y2 -y1, 2);
double distance = Math.Sqrt(xSquared+ ySquared);
return Content(distance.ToString(CultureInfo.InvariantCulture));
}
2011-4-17 16:16 danny