C# MVC4PartialView不显示为模式对话框,而是显示为自己的页面
我正在试验并试图学习如何使用更多的模态对话框,减少“视图跳跃”。我试图在Home/Index中显示_join.cshtml部分视图作为模式弹出窗口。相反,我得到的是C# MVC4PartialView不显示为模式对话框,而是显示为自己的页面,c#,asp.net-mvc-4,modal-dialog,asp.net-mvc-partialview,C#,Asp.net Mvc 4,Modal Dialog,Asp.net Mvc Partialview,我正在试验并试图学习如何使用更多的模态对话框,减少“视图跳跃”。我试图在Home/Index中显示_join.cshtml部分视图作为模式弹出窗口。相反,我得到的是 浏览器重定向到用户/加入并显示弹出窗口(如果我从用户控制器返回完整视图) 部分视图显示为自己的页面,不支持_Layout.cshtml视图中的.js和.css 我已经提供了下面的代码,如果能解开我目前所掌握的一切,我将不胜感激 控制器代码 public class UserController : Controller {
public class UserController : Controller
{
public ActionResult Join()
{
return PartialView("_join");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Join(Userprofile userprofile)
{
return PartialView("_join", userprofile);
}
}
名为_join.cshtml的部分视图
这位于“加入”视图文件夹中
你试图这样做的方式是不正确的 做这件事的步骤是
可能这有帮助,或者可能我误解了您的问题:)页面上是否有JavaScript错误?您是否检查了代码是否输入了if语句(if($('ModalUserJoin')。length>0))?我检查过。我也有同样的想法,在那里放了一个alert()进行测试,它确实起了作用。
@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>
if ($('#ModalUserJoin').length > 0) {
$('#ModalUserJoin').modal('show');
}
$(document).ready(function(){
var userModel = {name: "Donald Duck",city: "Duckburg"};
$("#userButton").click(function(){
$.post("User/Join",userModel ,
function(data, status){
$('body').append(data);
$('#ModalUserJoin').modal('show');
});
});
});