【问题标题】:Two different partial view using asp.net core 2.2 ,java script model ajax使用 asp.net core 2.2 的两个不同的局部视图,java 脚本模型 ajax
【发布时间】:2019-05-21 20:28:39
【问题描述】:

如何使用 Ajax 实现这一点?我得到了 JSON 格式的数据,但没有出现在弹出模型上。我有两个局部视图和一个主控制器 它没有显示模型,只弹出黑屏 在此先感谢

型号

public class OnboardModel
{
    //public string Userid { get; set; }

    public string NodeIdx { get; set; }

    public string Name{ get; set; }

    public string Address { get; set; }
}

控制器:仪表板/Getinfo

 public IActionResult Getxyzinfo(string nodeid = "7", string userid = "1" ,   string languageid = "1")
        {
            var RecentInfo = Buildxyzinfo(nodeidx, useridx, languageidx);

            return Json(new { success = true, recentinfoData = RecentInfo });
        }

html _index.cshtml局部视图

如何使用 ajax 创建新的局部调用

如何调用局部视图

JavaScript :

  <script type="text/javascript">
                            $(document).ready(function () {
                                $('#showGoogle').click(function () {
                                    var url = $('#myModal').data('url');

                                    $.get(url, function (data) {
                                        $('#googleContainer').html(data);

                                        $('#myModal').modal('show');

                                    });
                                });
                            });
                        </script>

_index.cshtml 部分视图

                            <div id='googleContainer'>
                            </div>
                        </div>

                        <a href="#" id="showGoogle">Invitation Business</a>
                    </div>

其他_getinfo.cshtml部分视图

<div class="container">
    <!-- Modal -->
    <div class="modal fade" id="googleContainer" role="dialog">
        <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        &times;
                    </button>
                    <h4 class="modal-title">
                        Serial Numbers
                    @*</h4>*@
                </div>
                <div class="modal-body">
                    <span id="test"></span>


    <p>Some text in the modal.</p>
                         @Html.LabelFor(model => model.Googlename, new { @class = "control-label col-md-2" })
 <span class"control-label col-md-3">@Html.DisplayFor(model => model.xyzitem.Googlename)</span>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        Close
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

【问题讨论】:

  • “如何调用局部视图”是什么意思?我看到你打电话给$('#partial').load(route); 不行吗?
  • 是的,这对我不起作用..
  • 那么哪个部分不起作用?服务器是否返回响应?
  • 不,我认为 Nodeidx 有问题 ...
  • 如果服务器没有respond,相信你应该检查一下服务器是否在运行。至少,你应该告诉我们服务器返回的状态码。

标签: jquery asp.net-core bootstrap-modal asp.net-ajax


【解决方案1】:
$(document).on("click", "#showmodal", function (nodeIdx) {

                $.ajax({
                    async: true,
                    url: '@Url.Action("Getxyzinfo", "Dashboard")',
                    data: { nodeIdx: nodeIdx },
                    type: 'GET',
                    traditional: true,
                    success: function (response) {
                        $("#googlecontanier").html(response.recentInfoData);

                        $("#myModal").modal("show");
                    },
                    error: function (xhr, status, error) {
                        console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
                    }
                });
            });

【讨论】:

  • 如果你解决了这个问题,请标记为答案:)
猜你喜欢
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
  • 2013-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多