1
我试图使用创建视图与索引视图来显示在同一页中创建的项目。 对于我使用_CreateCategory的局部视图和我添加以下内容索引视图子操作不允许执行重定向操作
{Html.RenderAction("Create", Model);}
我控制器的GET和POST方法如下用于创建
[HttpGet]
public ActionResult Create()
{
return PartialView("_CreateCategory",new Inventory.Models.Category());
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="Id,Description")] Category category)
{
if (ModelState.IsValid)
{
db.Categories.Add(category);
db.SaveChanges();
return RedirectToAction("Index");
}
return PartialView(category);
}
我的索引方法如下
public ActionResult Index()
{
return View(db.Categories.ToList());
}
我没有对部分视图做任何更改。我得到错误“
孩子的行为是不允许进行重定向操作
。我尝试过很多办法来克服这一点。但没有运气呢。
你是否用'[ChildActionOnly]'属性修饰了你的方法? –
不,我没有添加[ChildActionOnly]属性 – Snj