Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

javascript - 从asp.net Core2.2中的子模型获取Json值(Get Json value From Sub Model in asp.net Core2.2)

I'm using Ajax in my Asp.net core 2.2 which works just fine but I'm stack with the Json value which returns undefined since in the View I'm using a different way to post the Data in the page.

(我在Asp.net core 2.2中使用了Ajax,它工作正常,但是我与Json值堆叠在一起,该值返回undefined因为在View中,我使用了另一种方式将数据发布到页面中。)

How can ajax GET the correct data when My View looks like:

(当“我的视图”如下所示时,ajax如何GET正确的数据:)

<div class="treeview">
                        @{
                            if (Model._InstanceDepartment != null && Model._InstanceDepartment.Count() > 0)
                            {

                                <ul>
                                    @foreach (var i in Model._InstanceDepartment)
                                    {
                                        <li>
                                            <span class="collapse collapsible" data-loaded="false" pid="@i.DepartId">&nbsp;</span>
                                            <span>
                                                <a href="#@i.NavUrl" onclick="mydevpartmanifested()">@i.DepatName</a>

                                            </span>                                           
                                        </li>
                                    }
                                </ul>
                            }
                        }
                    </div>

And Ajax Get the Data from Controller Like

(和Ajax一样从Controller获取数据)

$.ajax({
                url: "/User/SubMenu",
                type: "GET",
                data: data,
                dataType: "json",
                success: function (d) {
                    $(this1).removeClass("loadingP");

                    if (d.length > 0) {

                        var $ul = $("<ul></ul>");
                        $.each(d, function (i, ele) {
                            $ul.append(
                                $("<li></li>").append(
                                    "<span class='collapse collapsible' data-loaded='false' pid='" + ele.DepartId + "'>&nbsp;</span>" +
                                    "<span><a href='" + ele.NavUrl + "'>" + ele.DepatName + "</a></span>"
                                )
                            )
                        });

                        $(this1).parent().append($ul);
                        $(this1).addClass('collapse');
                        $(this1).toggleClass('collapse expand');
                        $(this1).closest('li').children('ul').slideDown();
                    }
else{...} ../code continue just fine.

The problem is that I'm no getting the life of data from Model But from Model.__InstanceDepartment

(问题是我没有从Model而是从Model.__InstanceDepartment获取数据寿命)

VS2019 DEBUG show like:

(VS2019 DEBUG展示像:)

在此处输入图片说明

What I need is that the data which is found under _InstanceDepartment as shown on the picture, must be accessible in if(d.length > 0) to display the data.

(我所需要的是,这是根据找到的数据_InstanceDepartment上的画面如图所示,必须是在可访问的if(d.length > 0)以显示数据。)

Currently, it's displays none, undefined

(当前,不显示任何内容( undefined)

Anyone Has a Fast/Quick way to do this??

(有人有快速/快速的方法吗?)

  ask by PatsonLeaner translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...