【发布时间】:2012-08-24 17:13:05
【问题描述】:
我遇到了一个奇怪的问题。我的看法:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using(Html.BeginForm())
{
<input type="submit" value="asds"/>
}
@Html.Action("Index2")
我的控制器:
public class DefaultController : Controller
{
//
// GET: /Default1/
[HttpPost]
public ActionResult Index(string t)
{
return View();
}
public ActionResult Index()
{
return View();
}
//
// GET: /Default1/
[HttpPost]
public ActionResult Index2(string t)
{
return PartialView("Index");
}
[ChildActionOnly()]
public ActionResult Index2()
{
return PartialView();
}
}
当我点击一个按钮时,[HttpPost]Index(string t) 被执行,这很好。但在那之后[HttpPost]Index2(string t) 被执行,这对我来说真的很奇怪,因为我已经发布了Index 的数据,而不是Index2。我的逻辑告诉我[ChildActionOnly()]ActionResult Index2() 而不是HttpPost 一个。
为什么会这样?如何在不重命名 [HttpPost]Index2 操作的情况下覆盖此行为?
【问题讨论】:
标签: asp.net-mvc http-post child-actions