Danny
Danny

Reputation: 301

render partial view insted of other partial view

I have a form which is a partial view in layout page. I need after success to render another partial view in the first one place.

However the partial view is rendered inside the first partial view. (for example if user fill the form in Mydomain/index the new partial view should display in the same url. And now it is displayed in /controller/create).

[ChildActionOnly]
public ActionResult Create()
{
    ViewBag.SubjectId = new SelectList(db.subjects, "SubjectId", "Subjectname");
    return PartialView();
}

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "InfoId,FirstName,SureName,PhoneNumber,Address,Email,EnterdDate,IsActive,Tipol,SubjectId")] Info info)
    {

        info.EnterdDate = DateTime.Now;
        info.IsActive = false;
        if (ModelState.IsValid)
        {
            db.infos.Add(info);
            db.SaveChanges();
            TempData["thanks"] = info.FullName;
            return PartialView("_bla");
        }

        ViewBag.SubjectId = new SelectList(db.subjects, "SubjectId", "Subjectname", info.SubjectId);
        return View(info);
    }


    public PartialViewResult _bla()
    {
        var thanks = TempData["thanks"];
        return PartialView();
    }

Upvotes: 0

Views: 231

Answers (1)

Fabio
Fabio

Reputation: 11990

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "InfoId,FirstName,SureName,PhoneNumber,Address,Email,EnterdDate,IsActive,Tipol,SubjectId")] Info info)
{

        info.EnterdDate = DateTime.Now;
        info.IsActive = false;
        if (ModelState.IsValid)
        {
            db.infos.Add(info);
            db.SaveChanges();
            TempData["thanks"] = info.FullName;
            return RedirectToAction("Create");
        }

      ViewBag.SubjectId = new SelectList(db.subjects, "SubjectId", "Subjectname", info.SubjectId);
    return View(info);
    }

View Create:

@if (TempData["thanks"] != null)
{
    <div class="alert alert-success">
        @TempData["thanks"]
    </div>
}

// your form

Upvotes: 1

Related Questions