I'm experimenting and trying to learn how to use more modal dialogs and less "view jumping". What I was trying to do is in the Home/Index is display the _join.cshtml partial view as a modal popup. Instead what I get is either
The browser redirecting to User/Join and displaying the popup (if I return full View from the User controller)
The partial view displaying as it's own page without the .js and .css support that's in the _Layout.cshtml view.
I've provided the code below and would appreciate untangling what I have so far.
Controller code
public class UserController : Controller
{
public ActionResult Join()
{
return PartialView("_join");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Join(Userprofile userprofile)
{
return PartialView("_join", userprofile);
}
}
The partial view named _join.cshtml
This resides in the "join" views folder
@model DPDP.Models.Userprofile
<div id="ModalUserJoin" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="ModalUserJoinLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="ModalUserJoinLabel">Create An Account</h3>
</div>
<div class="modal-body">
<div class="embed-responsive embed-responsive-16by9">
@using (Ajax.BeginForm("Join", "User", FormMethod.Post, new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "POST" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
/* Form elements have been removed to save space */
}
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</div>
</div>
</div>
Javascript
This is to show the modal popup when the page loads and appears to work fine.
if ($('#ModalUserJoin').length > 0) {
$('#ModalUserJoin').modal('show');
}
The way you are trying to do it is incorrect.
Step to do it are ...
Bootstrap code to do so is this.(as i suppose you are using bootstrap)
Maybe this helps or maybe i misunderstood your problem :)