不允许子操作以我的模态形式执行重定向操作

时间:2016-03-29 12:46:39

标签: javascript asp.net-mvc bootstrap-modal

我的模态表单存在此错误:Child actions are not allowed to perform redirect actions.

这是我的控制者:

     public ActionResult Create()
     {
        return PartialView();
     }
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "Id,Title")] TypePart typePart)
    {
        try
        {
            if (ModelState.IsValid)
            {
                db.TypeParts.Add(typePart);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
        }
        catch
        {


        }
        return PartialView(typePart);
    }`

这是我的观点:

  <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Add</button>
 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria- labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Add</h4>
        </div>
        <div class="modal-body" id="bodymodal">
           @Html.Action("Create","TypeParts")

        </div>

    </div>
</div>

1 个答案:

答案 0 :(得分:0)

你试过了吗?
@Url.Action("Create","TypeParts")
而不是@Html.Action("Create","TypeParts")

根据解决方案here,它可以解决该问题