繁体   English   中英

在C#中返回View

[英]return View in C#

我是C#和ASP.NET MVC的新手,尤其是视图。

我有以下问题

我有这个代码

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult ManageEmployee(int cntID, string command)
    {
        //repository = new ContactRepository();
        cntadrRepository = new ContactAddressCountryRepository();
        //addressRepository = new AddressRepository();

        if (!String.IsNullOrEmpty(command) && command.Equals("edit"))
        {

            var cdrcnts = cntadrRepository.GetById(cntID);

            ViewBag.IsUpdate = true;
            //return View("_ManageEmployee", cdrcnts);
            return View("Index", cdrcnts);
            //return View("Index");
        }
        else
        {
            ViewBag.IsUpdate = false;
            //return View("_ManageEmployee");
            return View("Index");
        }
    }

当我单击“添加”按钮时,返回的表单为空

当我单击“添加”时,我将表格滑入并且网格滑出,可以输入新记录,然后单击“保存”后,我将返回带有新记录的网格。

现在的问题是,当我单击“编辑”时,我只有一个“添加”按钮的视图;当我单击“编辑”时,直接获得我想要获得的结果。

我认为返回视图时遇到问题。

我想要的是,当我单击“编辑”并停留在同一页面上时,该表单填满了联系信息,该页面再次显示网格和已编辑的记录,而没有需要单击“添加”按钮的空白页面再次获得所需的结果。

谢谢您的帮助。

<script type="text/javascript">
    $.ig.loader({
        scriptPath: './js/',
        cssPath: './css/',
        resources: 'igGrid.*',
        ready: function () {
            $.getJSON("Home/GetAll", null, function (data) {
                var headerTextValues = ["Relation to Will maker", "First Name", "Last Name","","",""];
                $('#employeeGrid').igGrid({
                    expandCollapseAnimations: true,
                    animationDuration: 1000,
                    expandTooltip: "Expand to View Details",
                    collapseTooltip: "Hide details",
                    height: "400px",
                    width: "800px",
                    dataSource: data,
                    responseDataKey: "Records",
                    //dataSourceType: "json",
                    autoGenerateLayouts: false,
                    autoGenerateColumns: false,

                    rowEditDialogContainment: "owner",
                    showReadonlyEditors: false,

                    columns: [
                        { headerText: headerTextValues[0], key: "cntID", width: 200 },
                        { headerText: headerTextValues[1], key: "cntFirstName", width: 175 },
                        { headerText: headerTextValues[2], key: "cntLastName", width: 175 },
                        //{ headerText: headerTextValues[3], key: "Age", width: 175 },
                        { headerText: headerTextValues[4], key: "UpdateRow", width: 110, template: "<a href='Home/ManageEmployee?cntID=${cntID}&command=edit' class='editDialog'>Edit</a>" },
                        { headerText: headerTextValues[5], key: "DeleteRow", width: 50, template: "<a href='Home/Delete?cntID=${cntID}' class='confirmDialog'><button>Delete</button></a>" },
                    ],

                    initialDataBindDepth: -1,
                    primaryKey: 'cntID',
                    width: '800',
                    updateURL: "Home/Update",

                    /*columnLayouts: [
                            {
                                key: "cntD",
                                responseDataKey: "Records",
                                autoGenerateColumns: false,
                                autoGenerateLayouts: false,
                                generateCompactJSONResponse: false,
                                primaryKey: "cntID",
                               foreignKey: "cntAddressID",
                                columns: [
                                    { key: "cntId", headerText: "Address Id", width: "150px" },
                                    { key: "cntAddressID", headerText: "Address", width: "150px" },
                                    //{ key: "Street", headerText: "Street", width: "150px" },
                                    //{ key: "City", headerText: "City", width: "150px" },
                                    //{ key: "Zip", headerText: "Zip", width: "150px" }
                                ]
                            }
                    ],*/

                    features: [
                            {
                                name: "Selection",
                                mode: "row",
                                multipleSelection: false
                            },
                            {
                                name: 'Hiding'
                            },
                            {
                                name: 'Paging',
                                type: 'local',
                                pageSize: 10,
                                inherit: true
                            },
                            {
                                name: 'Filtering'
                            },
                            {
                                name: "ColumnMoving",
                                mode: "immediate",

                                //columnDragStart: function (event, ui) {
                                //    ui.owner.element.find('tr td:nth-child(' + (ui.columnIndex + 1) + ')').addClass("ui-state-moving");
                                //    colMovingKey = ui.columnKey;
                                //},
                                //columnDragEnd: function (event, ui) {
                                //    var grid = $(event.target).data('igGrid');
                                //    var newindex = grid.options.columns.indexOf(grid.columnByKey(colMovingKey)) + 1;
                                //    grid.element.find('tr td:nth-child(' + newindex + ')').removeClass("ui-state-moving");
                                //},

                                addMovingDropdown: true,
                                mode: "deferred",
                                type: "render"
                            }


                    ],
                });
            });
        }
    });


    $(document).ready(function () {

        $.ajaxSetup({ cache: false });

        $(".editDialog").live("click", function (e) {

            e.preventDefault();
            var url = $(this).attr('href');
            $("#dialog-edit").load(url);
            $("#dialog-edit").toggle("slide");
        });

        $("#openDialog").live("click", function (e) {
            e.preventDefault();
            var url = $(this).attr('href');
            $("#dialog-create").load(url);
            $("#dialog-create").toggle("slide");
        })


    });


</script>
@section featured {
<section class="featured">
    <div class="overlap">
    <div class="content-wrapper">

        <!-- the igHierarchicalGrid target element-->
        <table id="employeeGrid" style="width: auto;"></table>

        <p>
            <a id='openDialog' href='Home/ManageEmployee?cntID=0&command=create' class='openDialog ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' style="color: white;">Add Employee</a>

        </p>
        <div id="btn">
        <button id="add">Add</button>
            </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM