小编Aru*_*r T的帖子

当ajax调用C#mvc控制器不起作用时处理会话超时

从ajax调用函数时.程序流程无法识别过期的会话,即不会重定向到登录页面.而不是那样,它保存了记录.我在c#.net mvc工作.那么如何在ajax调用时处理会话.我给了我的代码.

 $.ajax({ 
            type: "POST",
            url:'/Employee/SaveEmployee',
            data:
            {
                Location:$("#txtLocation").val(), 
                dateApplied:$("#txtDateApplied").val(), 
                Status:$("#ddStatus").val(), 
                mailCheck:$("#ddMailCheck").val(),
                ...
                ...
                ... 
            },
            success: function (result) 
            {

            },
            error: function (msg) 
            {
            }
      });
Run Code Online (Sandbox Code Playgroud)

在这里控制器

[Authorize]
public string SaveEmployee(string Location, string dateApplied, string Status, string mailCheck, ...)
{
      objEmpMain.FirstName = firstName;
      objEmpMain.LastName = lastName;
      objEmpMain.Initial = Initial;
      objEmpMain.Address1 = Address;
      ...
      ... 
      ...
} 
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc session-timeout

7
推荐指数
1
解决办法
2万
查看次数

将数据集导出到asp.net c中的excel表

我试图将有4个表的数据集导出到excel表,不幸的是我做不到.我有代码将数据表导出到excel.因此,我调用了"ExportToExcel"函数代替数据集,我在代码中将数据表导出为ex​​cel 4次.但是一旦它创建了第一张纸,就会停止控制流程.Control不调用第二个函数("ExportToExcel(dsResult.Tables [2],"AthleteSentCount");")这是代码

protected void ExportToExcel(object sender, EventArgs e)
{
     ExportToExcel(dsResult.Tables[3], "AthleteInboxCount");
     ExportToExcel(dsResult.Tables[2], "AthleteSentCount");
     ExportToExcel(dsResult.Tables[0], "CoachInboxCount");
     ExportToExcel(dsResult.Tables[1], "CoachSentCount");
}

void ExportToExcel(DataTable dt, string FileName)
{
    if (dt.Rows.Count > 0)
    {
        string filename = FileName + ".xls";
        System.IO.StringWriter tw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
        DataGrid dgGrid = new DataGrid();
        dgGrid.DataSource = dt;
        dgGrid.DataBind();

        //Get the HTML for the control.
        dgGrid.RenderControl(hw);
        //Write the HTML back to the browser.
        //Response.ContentType = application/vnd.ms-excel;
        Response.ContentType = "application/vnd.ms-excel";
        Response.AppendHeader("Content-Disposition", 
                              "attachment; filename=" + filename …
Run Code Online (Sandbox Code Playgroud)

c# asp.net export-to-excel

7
推荐指数
1
解决办法
5万
查看次数