TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ankit Kumar
NA
159
48.3k
Data export is not working in asp .net MVC
Aug 21 2017 6:02 AM
Dear Friends
i am trying to export list data to excel but neither i am getting any error nor my my task is getting accomplished, no excel file is being downloaded.
someone please help.
code is given below
public ActionResult lnkExportData()
{
EmployeeHome EmpHome = new EmployeeHome();
List<EmployeeHome> objEmployeeList = new List<EmployeeHome>();
EmpHome.BindEmployee(1, "", "", "", "");
var list = EmpHome.ListLanguageEmployee;
var Records = list.Select(x => new { UserName = x.UserName, Name = x.ImageFilePath + ' ' + x.LastName + '-' + '(' + x.EmpCode + ')', Designation = x.Designation, CellularNumber = x.CellPhone, EmailID = x.EmailId, JoiningDate = String.Format("{0:dd-MMM-yyyy}", x.JoiningDate), Status = x.Status == 1 ? "Active" : "Inactive" }).ToList();
var gv = new GridView();
gv.DataSource = Records;
gv.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=DemoExcel.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter objStringWriter = new StringWriter();
HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);
gv.RenderControl(objHtmlTextWriter);
Response.Output.Write(objStringWriter.ToString());
Response.Flush();
Response.End();
return View();
}
Reply
Answers (
8
)
Which is secure from ViewData, ViewBag, and TeampData ?
not all code paths return a value