i ve got a weird problem. My view :
@{
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
操作的情况下覆盖此行为?