Oct 10, 2012, 7:35 AM
[Razor] Error occurs when export Excel file from GridPanel
My Controller is here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Xml;
using System.Xml.Xsl;
namespace Layout.Controllers
{
public class ExportExcelController : Controller
{
public ActionResult Index()
{
return View("ViewAlarmReport","Index");
}
[HttpPost]
public ActionResult ToExcel(string data)
{
Ext.Net.SubmitHandler submitData = new Ext.Net.SubmitHandler(data);
XmlNode xml = submitData.Xml;
XslCompiledTransform xtCsv = new XslCompiledTransform();
xtCsv.Load(Server.MapPath("/Resources/xls/Excel.xls"));
StringBuilder s = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings()
{
ConformanceLevel = ConformanceLevel.Auto
};
XmlWriter writer = XmlWriter.Create(s, settings);
xtCsv.Transform(xml, writer);
var result = new FileContentResult(Encoding.UTF8.GetBytes(s.ToString()), "application/octet-stream");
result.FileDownloadName = "Temp.csv";
return result;
}
}
}
My View Here:@{
DateTime now2 = DateTime.Now;
var dataAlarmRe = new object[]
{
new object[] {"35 RUTA", "Input 2 inactive", now2, now2, "Valid", "41.744833,44.779036", "41.744833", "44.779036", "0.00"},
new object[] {"35 RUTA", "Input 2 inactive", now2, now2, "Valid", "41.744833,44.779036", "41.744833", "44.779036", "0.00"},
new object[] {"35 RUTA", "Input 2 inactive", now2, now2, "Valid", "41.744833,44.779036", "41.744833", "44.779036", "0.00"},
new object[] {"35 RUTA", "Input 2 inactive", now2, now2, "Valid", "41.744833,44.779036", "41.744833", "44.779036", "0.00"},
new object[] {"35 RUTA", "Input 2 inactive", now2, now2, "Valid", "41.744833,44.779036", "41.744833", "44.779036", "0.00"},
new object[] {"35 RUTA", "Input 2 inactive", now2, now2, "Valid", "41.744833,44.779036", "41.744833", "44.779036", "0.00"},
new object[] {"35 RUTA", "Input 2 inactive", now2, now2, "Valid", "41.744833,44.779036", "41.744833", "44.779036", "0.00"},
};
Html.X()...................................}).Html.X().Button().ID("Export_Excel").IconUrl("../../Content/images/excel.gif").DirectEvents(DirEvAlarmExcel =>
{
DirEvAlarmExcel.Click.Url = Url.Action("ToExcel", "ExportExcel");
DirEvAlarmExcel.Click.IsUpload = true;
DirEvAlarmExcel.Click.EventMask.ShowMask = true;
DirEvAlarmExcel.Click.ExtraParams.Add(new Parameter()
{
Name = "data",
Value = "#{AlarmGridPanel}.getRowsValues()",
Mode = ParameterMode.Raw,
Encode = true,
});
DirEvAlarmExcel.Click.ExtraParams.Add(new Parameter()
{
Name = "format",
Value = "xls",
Mode = ParameterMode.Value
});
}));//Alarm Button Excel------------------------
Html.X()...................................}).Items(
AlarmItemGrid => {
AlarmItemGrid.Add(Html.X().GridPanel().ID("AlarmGridPanel").Title("Alarm Details").Border(false)
.Store(AlarmItemGridStore => {
AlarmItemGridStore.Add(Html.X().Store().AutoLoad(true).Model(AlarmItemGridStoreModel => {
AlarmItemGridStoreModel.Add(Html.X().Model().Fields(AlarmItemGridStoreField => {
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-device-name"));
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-type"));
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-gps-time"));
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-recive-time"));
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-fix"));
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-location"));
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-latitude"));
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-longtitude"));
AlarmItemGridStoreField.Add(Html.X().ModelField().Name("grid-alarm-speed"));
}));
}).DataSource(dataAlarmRe));
})
.ColumnModel(coModelAlarm =>
{
coModelAlarm.Add(Html.X().Column().Text("Device Name").DataIndex("grid-alarm-device-name"));
coModelAlarm.Add(Html.X().Column().Text("Alarm Type").DataIndex("grid-alarm-type"));
coModelAlarm.Add(Html.X().Column().Text("GPS Time").DataIndex("grid-alarm-gps-time"));
coModelAlarm.Add(Html.X().Column().Text("Recived Time").DataIndex("grid-alarm-recive-time"));
coModelAlarm.Add(Html.X().Column().Text("Fix").DataIndex("grid-alarm-fix"));
coModelAlarm.Add(Html.X().Column().Text("Location").DataIndex("grid-alarm-location"));
coModelAlarm.Add(Html.X().Column().Text("Speed").DataIndex("grid-alarm-latitude"));
coModelAlarm.Add(Html.X().Column().Text("Latitude").DataIndex("grid-alarm-longtitude"));
coModelAlarm.Add(Html.X().Column().Text("Longtitude").DataIndex("grid-alarm-speed"));
}));
}
)//Alarm Item Grid
When I click the button to Export, It have error:
Last edited by delta; Oct 10, 2012 at 9:05 AM.