asp.net mvc 小心Html.RenderAction

在mvc的view上使用Html.RenderAction显示另外一些分布视图时要注意
Html.RenderAction在调用具体action的时候,会和主action的method有关;
主action是get,他也是get,主method是post,他也调post。
 
简单代码演示
在主action对应的view中,通过Html.RenderAction调用action a。
@{
    Html.RenderAction("a");
}

@using(Html.BeginForm())
{
    <input type="submit" />
}

 

仅为演示controller里也很简单

 

public ActionResult Index()
{
    return View();
}
[HttpPost]
public ActionResult Index(FormCollection form)
{
    return View();
}
public ActionResult A()
{
    return Content("get");
}
[HttpPost]
public ActionResult A(FormCollection form)
{
    return Content("post");
}

执行

image

点按钮post

image

action a调的是post版的。

 

人生无处不陷阱

posted @ 2011-11-11 13:18  czcz1024  阅读(483)  评论(0)    收藏  举报