How should you implement the ExecuteResult method?

You are developing an ASP.NET MVC web application that enables users to open Microsoft
Excel files. The current implementation of the ExcelResult class is as follows.

You need to enable users to open Excel files. How should you implement the ExecuteResult
method? (To answer, select the appropriate options in the answer area.)

You are developing an ASP.NET MVC web application that enables users to open Microsoft
Excel files. The current implementation of the ExcelResult class is as follows.

You need to enable users to open Excel files. How should you implement the ExecuteResult
method? (To answer, select the appropriate options in the answer area.)

Answer:



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Maurizio

Maurizio

public override void ExecuteResult(ControllerContext context)
{
var response = context.HttpContext.Response;
var request = context.HttpContext.Request;

var canProcess = request.AcceptTypes.Contains(“application/vnd.ms-excel”);

if (canProcess)
{
response.Clear();
response.AddHeader(“content-disposition”, “attachment;filename=dl.xlsx”);

response.ContentType = “application/vnd.ms-excel”;

response.WriteFile(context.HttpContext.Server.MapPath(Path));
}
}