C# C语言中的返回视图

C# C语言中的返回视图,c#,javascript,asp.net-mvc,C#,Javascript,Asp.net Mvc,我不熟悉C和ASP.NET MVC,特别是视图 我有以下问题 我有这个密码 [AcceptVerbs(HttpVerbs.Get)] public ActionResult ManageEmployee(int cntID, string command) { //repository = new ContactRepository(); cntadrRepository = new ContactAddressCountryReposit

我不熟悉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");
        }
    }
当我点击Add按钮时,返回空的表单

当我点击Add时,我得到表单滑入和网格滑出,我可以输入一条新记录,然后在点击save后,我带着新记录返回我的网格

现在的问题是,当我点击编辑时,我的视图只有一个添加按钮,当我点击编辑时,我会直接得到我想要得到的结果,编辑是填写了所需信息的表单

当我返回视图时,我认为我有一个问题

我想要的是,当我单击“编辑”时,返回填充了联系人信息的表单,并停留在再次显示网格和编辑记录的同一页面中,而不是带有添加按钮的空页面,我需要再次单击该按钮才能获得所需的结果


谢谢您的帮助。

我以前会尝试MVC演练,因为您是.NET中MVC的新手。尝试:如果你想提交更改并在视图中不重定向,你必须通过ajax发布表单,然后重新加载你的窗口谢谢你的建议,但你能给我一个例子吗?@mailmond感谢你提供了有趣的链接,但我不想为编辑表单创建单独的视图。我有一个表单,更新函数同时扮演两个角色:创建和更新。创建工作正常,但当涉及到编辑时,会发送一个新视图,这不是我想要的。我想停留在同一个页面上,使用相同的动画,只是表单将被填充,而不是empty@AntarrByrd感谢您提供了有趣的链接,但我不想为编辑表单创建单独的视图。我有一个表单,更新函数同时扮演两个角色:创建和更新。创建工作正常,但当涉及到编辑时,会发送一个新视图,这不是我想要的。我想停留在同一个页面上,使用相同的动画,只是表单将被填充而不是空的
<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>