0

在发布到父控制器之前,如何强制弹出页面先发布到其控制器?弹出页面正在设置一些将在父页面中使用的会话变量。当用户双击弹出页面上的网格时,它会直接转到父控制器,而不是转到子控制器。

这是调用弹出窗口的父级

//Javascript to open the popup window

@using (Html.BeginForm("Student", "StudentPage", FormMethod.Get, new { onsubmit = "", id = "student" }))
{
//where the popup window is located
}

这是弹出表单:

@using (Html.BeginForm("Index", "StudentInformation", FormMethod.Post, new {id="StudentSearchForm"}))
{ 
   @(Html
    .Telerik()
    .Grid((IEnumerable<OverrideStudent>)SessionWrapper.Student.OtherStudentSelected)
    .Name("StudentData")
    .DataKeys(Keys =>
    {
        Keys.Add(c => c.StudentID);
    })
    .DataBinding(databinding => databinding.Server())
    .Columns(columns =>
    {
        columns.Bound(p => p.StudentId)
            .Title("Student ID")
            .Width(15)
            .Sortable(true)
            .Filterable(false);
        columns.Bound(p => p.StudentDescription)
            .Title("Description")
            .Width(65)
            .Sortable(true)
            .Filterable(false);
        columns.Command(command =>
        {
            command.Custom("AddStudent")
                .Text("Select")
                .DataRouteValues(routes =>
                {
                    routes.Add(o => o.StudentID).RouteKey("StudentID");
                    routes.Add(o => o.StudentDescription).RouteKey("StudentDescription");
                })
                .Action("Student", "StudentInfo");
             .HtmlAttributes(new { onclick = "PostData(this);StudentSelectClick(this)" });

        }).Width(20);
    }).ClientEvents(clients => clients
            .OnComplete("OnComplete")
        //.OnDataBinding("DataBinding")
        //.OnDataBound("onRowDataBound")
            .OnRowSelected("StudentDoubleClick")
            )
    .Sortable()
    .Selectable()
    .Filterable(filtering => filtering
                .Enabled(true)
    .Footer(true)
    .HtmlAttributes(new { style = "padding-right: 0.0em;" }))
}

//这是处理双击的脚本:

function StudentDoubleClick(e) {
        var fromCourse = "@SessionWrapper.Student.FromCoursePage";
        var fromList = "@SessionWrapper.Student.FromListingPage";
        if (fromCourse  == "True") {
            $('tr', this).live('dblclick', function () {
                alert("Inside TR count = " + count);
                count = count + 1;
                DoSearchStudent(e);
            });
        }

        if (fromList == "True") {
            $('tr', this).live('dblclick', function () {
                DoSearchStudent(e);
            });
        }
    }



function DoSearchStudent(e) {
        var row = e.row;
        var StudentID = row.cells[0].innerHTML;
        var StudentDescription = row.cells[1].innerHTML;
        //  alert(procCodeDesc);
        var data = { "StudentID": StudentID, "StudentDescription": StudentDescription, "action": "Double Click" };
        var url = '@Url.Action("Student", "StudentInfo")';
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'text',
            cache: false,
            async: false,
            data: data,
            success: function (data) {
                window.top.location.href = window.top.location.href;
            },
            error: function (error) {
                alert("An error has occured and the window will not be closed.");

            }
        });
    }

//这是我需要先去的控制器

public class StudentInfoController : Controller
    {
        .......

    public string Student(string StudentID, string StudentDescription, string action)
        {
            if (StudentDescription != null)
            {
                StudentDescription = HttpUtility.HtmlDecode(StudentDescription);
            }

            try
            {
                RedirectToAction("AddStudent", "StudentInfo", new { StudentID = StudentID, StudentDescription = StudentDescription, action = action });
            }
            catch (Exception e)
            {
                return "Error " + e.ToString(); 
            }

            return "Success";
        }
}

双击后,它直接转到下面的控制器。结果,我的变量没有被设置导致空异常。

public class StudentPageController : Controller
    {
        .......

    public string Student(string StudentID, string StudentDescription, Student Students)
        {
            ...........
        }
}
4

1 回答 1

0

这是一个时间问题。当用户关闭弹出窗口时,弹出线程没有完成执行。与此同时,另一个线程开始运行,但尚未设置所有会话变量。在关闭弹出窗口之前,我添加了 1 秒延迟。setTimeout('StudentWindow.close()', 1000);

于 2013-06-25T12:32:03.153 回答