Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC4PartialView不显示为模式对话框,而是显示为自己的页面_C#_Asp.net Mvc 4_Modal Dialog_Asp.net Mvc Partialview - Fatal编程技术网

C# MVC4PartialView不显示为模式对话框,而是显示为自己的页面

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 {

我正在试验并试图学习如何使用更多的模态对话框,减少“视图跳跃”。我试图在Home/Index中显示_join.cshtml部分视图作为模式弹出窗口。相反,我得到的是

  • 浏览器重定向到用户/加入并显示弹出窗口(如果我从用户控制器返回完整视图)

  • 部分视图显示为自己的页面,不支持_Layout.cshtml视图中的.js和.css

  • 我已经提供了下面的代码,如果能解开我目前所掌握的一切,我将不胜感激

    控制器代码

    public class UserController : Controller
    {
        public ActionResult Join()
        {
            return PartialView("_join");
        }
    
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Join(Userprofile userprofile)
        {
            return PartialView("_join", userprofile);
        }
    }
    
    名为_join.cshtml的部分视图

    这位于“加入”视图文件夹中


    你试图这样做的方式是不正确的

    做这件事的步骤是

  • 加载索引页
  • 对像onload、onClick这样的事件发出ajax post请求,使用javascript向页面用户/加入
  • 在ajax请求中,您将获得弹出模型的html字符串
  • 然后使用html字符串触发弹出显示事件
  • 这样做的引导代码如下所示。(我假设您正在使用引导)


    可能这有帮助,或者可能我误解了您的问题:)

    页面上是否有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');
    });
    });
    });