Reputation: 915
There is a view for registration that has two PartialView in jquery tab (register by phone or register by email).
I was Called those in Parent view with below codes:
<div id="tabs" class="tabs">
<nav>
<ul>
<li><a href="#section-1" class="fa fa-mobile"><span>موبایل</span></a></li>
<li><a href="#section-2" class="fa fa-envelope"><span>ایمیل</span></a></li>
</ul>
</nav>
<div class="content">
<section id="section-1">
@Html.Partial("_MobileRegister", new S6.ViewModels.MobileRegister())
</section>
<section id="section-2">
@Html.Partial("_EmailRegister" , new S6.ViewModels.EmailRegister())
</section>
</div>
</div>
controller and actions:
public ActionResult Register()
{
return View();
}
public PartialViewResult _MobileRegister()
{
return PartialView("_MobileRegister");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult MobileRegister(MobileRegister model)
{
if (ModelState.IsValid)
{
}
return PartialView("~/Views/Account/_MobileRegister.cshtml", model);
}
Now, when data post to action, if the ModelState
is not valid or for any reason that causes the return PartialView
to be called, PartialView is shown in seprated page.
What is wrong?
Upvotes: 0
Views: 78
Reputation: 915
I found a complete example here:
https://www.pluralsight.com/guides/asp-net-mvc-using-ajax-helpers-with-razor-partial-views
Upvotes: 0
Reputation: 167
if you want to render "Partial Views" on the other view, you have to use Ajax instead direct post. Ajax.BeginForm
is a good solution.
Upvotes: 1
Reputation: 47
If you don't return anything in the
if (ModelState.IsValid)
{
}
your funtion will always return the PartialView. Add a return statement in that if.
Upvotes: 2