JS网格未在Partial View MVC中显示

时间:2018-08-03 07:15:30

标签: asp.net-mvc jsgrid

在我的项目中,我从局部视图显示js网格。如此尝试

查看

    <div id="searchgrid" class="col-lg-12">
       @Html.Partial("ResultGrid", new List<SCM_MVC.Models.User>(), new ViewDataDictionary(this.ViewData) { { "index" , ViewData["Form"] } })
    </div>
<script src="~/assets/js/jquery-1.10.2.js"></script>
<script>
    var url = '@Url.Action("ResultGrid", "User", new { xEdit = ViewData["Form"]})';
    $('#btnloadgrid').click(function () {
        $('#searchgrid').load(url);
    })
</script>

局部视图

@model IEnumerable<SCM_MVC.Models.User>

@{
    /**/

    /**/
    @section head {
        @*<link rel="stylesheet" type="text/css" href="~/SCM/jsgrid/css/demos.css" />*@
        <link rel="stylesheet" type="text/css" href="~/SCM/jsgrid/css/jsgrid.css" />
        <link rel="stylesheet" type="text/css" href="~/SCM/jsgrid/css/theme.css" />

        <script src="~/SCM/jsgrid/js/jquery-1.8.3.js"></script>

        <script src="~/SCM/jsgrid/src/jsgrid.core.js"></script>
        <script src="~/SCM/jsgrid/src/jsgrid.load-indicator.js"></script>
        <script src="~/SCM/jsgrid/src/jsgrid.load-strategies.js"></script>
        <script src="~/SCM/jsgrid/src/jsgrid.sort-strategies.js"></script>
        <script src="~/SCM/jsgrid/src/jsgrid.field.js"></script>
        <script src="~/SCM/jsgrid/src/jsgrid.core.js"></script>
        <script src="~/SCM/jsgrid/src/fields/jsgrid.field.text.js"></script>
        <script src="~/SCM/jsgrid/src/fields/jsgrid.field.number.js"></script>
        <script src="~/SCM/jsgrid/src/fields/jsgrid.field.select.js"></script>
        <script src="~/SCM/jsgrid/src/fields/jsgrid.field.checkbox.js"></script>
        <script src="~/SCM/jsgrid/src/fields/jsgrid.field.control.js"></script>

    }
    /**/
        <table id="jsGrid"></table>
        @section scripts {
            <script src="http://js-grid.com/js/jsgrid.min.js"></script>
            <script>
                $(function () {

                    $("#jsGrid").jsGrid({
                        height: "70%",
                        width: "100%",
                        filtering: true,
                        editing: true,
                        inserting: true,
                        sorting: true,
                        paging: true,
                        autoload: true,
                        pageSize: 15,
                        pageButtonCount: 5,
                        deleteConfirm: "Do you really want to delete the user?",
                        controller: {
                            loadData: function (filter) {
                                return $.ajax({
                                    type: "GET",
                                    url: "/api/data",
                                    data: filter,
                                    dataType: "json"
                                });
                            },

                            insertItem: function (item) {
                                return $.ajax({
                                    type: "POST",
                                    url: "/api/data",
                                    data: item,
                                    dataType: "json"
                                });
                            },

                            updateItem: function (item) {
                                return $.ajax({
                                    type: "PUT",
                                    url: "/api/data/" + item.ID,
                                    data: item,
                                    dataType: "json"
                                });
                            },

                            deleteItem: function (item) {
                                return $.ajax({
                                    type: "DELETE",
                                    url: "/api/data/" + item.ID,
                                    dataType: "json"
                                });
                            }
                        },
                        fields: [
                            { name: "user_id", title: Resources.Resource.user_id, type: "text", width: 150 },
                            { name: "username", title: Resources.Resource.user_name, type: "text", width: 50 },
                            { name: "mailid", title: Resources.Resource.mailid, type: "text", width: 200 },
                            { name: "role", title: Resources.Resource.role, type: "text", width: 50 },
                            { name: "dept", title: Resources.Resource.dept, type: "text", width: 100 },
                            { name: "designation", title: Resources.Resource.designation, type: "text", width: 100 },
                            { name: "city", title: Resources.Resource.city, type: "text", width: 100 },
                            { name: "country", title: Resources.Resource.country, type: "text", width: 100 },
                            { type: "control" }
                        ]
                    });
                });
            </script>
        }

}

DataController

namespace SCM_MVC.Controllers
{
    public class DataController : ApiController
    {
        // GET: Data
        public IEnumerable<object> Get()
        {
            //ClientFilter filter = GetFilter();

            //var result = DB.Client.Where(c =>
            //    (String.IsNullOrEmpty(filter.Name) || c.Name.Contains(filter.Name)) &&
            //    (String.IsNullOrEmpty(filter.Address) || c.Address.Contains(filter.Address)) &&
            //    (!filter.Married.HasValue || c.Married == filter.Married) &&
            //    (!filter.Country.HasValue || c.Country == filter.Country)
            //);

            Models.User xuser = new Models.User();
            List<Models.User> xuserlist = new List<Models.User>();

            //if (ViewData["index"] == null)
            //{
            //    ViewData["index"] = xEdit;
            //}

            xuser.UserId = "US-0001";
            xuser.UserName = "Robert";
            xuser.Mailid = "robert@gmail.com";
            xuser.Role = "Admin";
            xuser.Designation = "Sales Admin";
            xuser.Dept = "Sales";
            xuser.State = "Tamil Nadu";
            xuser.Country = "India";
            xuserlist.Add(xuser);

            return xuserlist;
        }
    }
}

UserController

 public ActionResult ResultGrid(string xEdit)
        {

            Models.User xuser = new Models.User();
            List<Models.User> xuserlist = new List<Models.User>();
            xuser.UserId = "US-0001";
            xuser.UserName = "Robert";
            xuser.Mailid = "robert@gmail.com";
            xuser.Role = "Admin";
            xuser.Designation = "Sales Admin";
            xuser.Dept = "Sales";
            xuser.State = "Tamil Nadu";
            xuser.Country = "India";
            xuserlist.Add(xuser);

            return PartialView(xuserlist);
        }

但是在屏幕上没有显示。这是怎么了? 谢谢

我正在使用 Visual Studio 2017 ASP.Net MVC

0 个答案:

没有答案