0

I have a problem in my modal form with this error: Child actions are not allowed to perform redirect actions.

This is my controller:

     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);
    }`

And this is my view:

  <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>

Jens
  • 6,275
  • 2
  • 25
  • 51
saleh azami
  • 13
  • 1
  • 7

1 Answers1

0

Did you tried;
@Url.Action("Create","TypeParts")
instead of
@Html.Action("Create","TypeParts")

According to solution here, it may solve that problem

Community
  • 1
  • 1
Qsprec
  • 265
  • 3
  • 11