Как передать Excel файл клиенту

21 views
Skip to first unread message

Viktor Sirchenko

unread,
Sep 8, 2014, 1:55:09 AM9/8/14
to ext...@googlegroups.com
Всем привет, пытаюсь решить проблему передачи файл клиенту использую DirectEvents
на сервере все просто:

return this.File(@path, "application/ms-excel", "Имя файла.xls");

но вот у клиента после этого выходит все что:


Daniil Veriga

unread,
Sep 8, 2014, 2:46:07 AM9/8/14
to ext...@googlegroups.com
Привет!

Есть ли IsUpload="true" для DirectEvent-а?

--
Вы получили это сообщение, поскольку подписаны на группу "Ext.NET".
Чтобы отменить подписку на эту группу и больше не получать от нее сообщения, отправьте письмо на электронный адрес extnet+un...@googlegroups.com.
Чтобы настроить другие параметры, перейдите по ссылке https://groups.google.com/d/optout.

Viktor Sirchenko

unread,
Sep 8, 2014, 2:51:31 AM9/8/14
to ext...@googlegroups.com
Нет, я его ставил и у меня выходила непонятная ошибка

.DirectEvents(x =>
                   
{
                        x
.Click.Method = Ext.Net.HttpMethod.POST;
                        x
.Click.IsUpload = true;
                        x
.Click.Url = Url.Action("Generate", "ReportCashSeparate");
                        x
.Click.ExtraParams.Add(new Parameter("date", "getDateValue()", ParameterMode.Raw));
                        x
.Click.ExtraParams.Add(new Parameter("currencyID", "getCurrencyValue()", ParameterMode.Raw));
                        x
.Click.ExtraParams.Add(new Parameter("organizationID", "getOrganizationValue()", ParameterMode.Raw));
                        x
.Click.ExtraParams.Add(new Parameter("specificityID", "getSpecificityValue()", ParameterMode.Raw));
                        x
.Click.ExtraParams.Add(new Parameter("programID", "getProgramValue()", ParameterMode.Raw));
                        x
.Click.ExtraParams.Add(new Parameter("articleExpendureID", "getArticleExpendureValue()", ParameterMode.Raw));
                   
}),
делаю так и получаю
Server Error in '/' Application. The parameters dictionary contains a null entry for parameter 'programID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Generate(System.String, Int32, Int32, Int32, Int32, Int32)' in 'WebClient.Controllers.ReportCashSeparateController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.Parameter name: parameters Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'programID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Generate(System.String, Int32, Int32, Int32, Int32, Int32)' in 'WebClient.Controllers.ReportCashSeparateController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.Parameter name: parameters Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [ArgumentException: The parameters dictionary contains a null entry for parameter 'programID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Generate(System.String, Int32, Int32, Int32, Int32, Int32)' in 'WebClient.Controllers.ReportCashSeparateController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters] System.Web.Mvc.ActionDescriptor.ExtractParameterFromDictionary(ParameterInfo parameterInfo, IDictionary`2 parameters, MethodInfo methodInfo) +607775 System.Web.Mvc.<>c__DisplayClass1.b__0(ParameterInfo parameterInfo) +18 System.Linq.WhereSelectArrayIterator`2.MoveNext() +66 System.Linq.Buffer`1..ctor(IEnumerable`1 source) +335 System.Linq.Enumerable.ToArray(IEnumerable`1 source) +77 System.

и еще много всякого текста
 

Daniil Veriga

unread,
Sep 8, 2014, 2:53:19 AM9/8/14
to ext...@googlegroups.com
IsUpload="true" необходим.

Что касается Exception, то уходит ли этот параметр с запросом?


x.Click.ExtraParams.Add(new Parameter("programID", "getProgramValue()", ParameterMode.Raw));

--

Viktor Sirchenko

unread,
Sep 8, 2014, 2:56:15 AM9/8/14
to ext...@googlegroups.com
Я написал метод на клиенте, что если не выбран параметр должен идти 0. но видимо это не так

var getProgramValue = function () {
        if (App.ProgramID.getValue() != null)
            return App.ProgramID.getValue();
        else
            return 0;
    };



понедельник, 8 сентября 2014 г., 12:53:19 UTC+6 пользователь Daniil написал:

Viktor Sirchenko

unread,
Sep 8, 2014, 3:11:42 AM9/8/14
to ext...@googlegroups.com
Прописал в Каждом поле .Value(0), все заработало, но когда открываешь форму и на ней в поле 0, как то не красиво смотрится

понедельник, 8 сентября 2014 г., 11:55:09 UTC+6 пользователь Viktor Sirchenko написал:

Daniil Veriga

unread,
Sep 8, 2014, 3:18:16 AM9/8/14
to ext...@googlegroups.com
Я бы подебажил getProgramValue, чтобы убедиться уходит 0 или нет.

И/или глянуть в запросе для начала.

Viktor Sirchenko

unread,
Sep 8, 2014, 3:21:31 AM9/8/14
to ext...@googlegroups.com
Еще хочу вопрос в тему, выложил проект на другую машину, у меня все работает нормально, а вот на другой в консоли выдает вот такое

Resource interpreted as Document but transferred with MIME type application/json:




понедельник, 8 сентября 2014 г., 13:18:16 UTC+6 пользователь Daniil написал:

Daniil Veriga

unread,
Sep 8, 2014, 3:36:14 AM9/8/14
to ext...@googlegroups.com
Не знаю. Я бы погуглил.

Viktor Sirchenko

unread,
Sep 8, 2014, 4:18:53 AM9/8/14
to ext...@googlegroups.com
Продебажил, если выводить через console.info правильно

но выходит что отправляет 0


понедельник, 8 сентября 2014 г., 13:18:16 UTC+6 пользователь Daniil написал:
Я бы подебажил getProgramValue, чтобы убедиться уходит 0 или нет.

Viktor Sirchenko

unread,
Sep 8, 2014, 4:22:42 AM9/8/14
to ext...@googlegroups.com
вот что в Network вышло

  1. ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="Date" 08.09.2014 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="CurrencyID" 1 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="OrganizationID" 1 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="ProgramID" ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="SpecificityID" 0 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="_SpecificityID_state" [{"value":0}] ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="ArticleExpendureID" 0 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="_ArticleExpendureID_state" [{"value":0}] ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="date" "2014-09-08T00:00:00" ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="currencyID" 1 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="organizationID" 1 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="specificityID" 0 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="programID" 0 ------WebKitFormBoundaryL93xaeUZBK0QMHs4 Content-Disposition: form-data; name="articleExpendureID" 0 ------WebKitFormBoundaryL93xaeUZBK0QMHs4--


только почему они 2 раза передавались, может не использовать FormPanel? 

Daniil Veriga

unread,
Sep 8, 2014, 6:27:05 AM9/8/14
to ext...@googlegroups.com
только почему они 2 раза передавались

Видимо, один раз с сабмитом FormPanel (что автоматом происходит, если DirectEvent может найти форму для сабмита), а второй раз с ExtraParams. Можно избежать авто сабмита, если поставить Type="Load" для DirectEvent-а.

--

Viktor Sirchenko

unread,
Sep 8, 2014, 2:50:45 PM9/8/14
to ext...@googlegroups.com

Поставил x.Click.Type = DirectEventType.Load;
и у меня выходит тоже что и в самом начале

Viktor Sirchenko

unread,
Sep 8, 2014, 5:11:54 PM9/8/14
to ext...@googlegroups.com
Продолжаю тему, так как вопрос остается не решенным
Проект при запуске со студии работает нормально, файл передается клиенту для сохранения, но вот когда я перенес проект, на этой же машине просто на IIS, у меня выдало странное сообщение когда я должен был получить запрос на сохранение файла:

Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 354: finally Line 355: { Line 356: //app.DefaultSaveFormat = Excel.XlFileFormat.xlHtml; Line 357: Line 358: workbook.Saved = true; Source File: c:\PROJECTS\WebMFA\WebClient\Controllers\ReportCashSeparateController.cs    Line: 356 Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] WebClient.Controllers.ReportCashSeparateController.Generate(String date, Int32 currencyID, Int32 organizationID, Int32 programID, Int32 specificityID, Int32 articleExpendureID) in c:\PROJECTS\WebMFA\WebClient\Controllers\ReportCashSeparateController.cs:356 lambda_method(Closure , ControllerBase , Object[] ) +330 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +260 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +38 System.Web.Mvc.Async.<>c__DisplayClass42.b__41() +33 System.Web.Mvc.Async.<>c__DisplayClass39.b__33() +123 System.Web.Mvc.Async.<>c__DisplayClass4f.b__49() +838827 System.Web.Mvc.Async.<>c__DisplayClass37.b__36(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c__DisplayClass2a.b__20() +33 System.Web.Mvc.Async.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) +839412 System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51 System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408

Daniil Veriga

unread,
Sep 9, 2014, 9:27:15 AM9/9/14
to ext...@googlegroups.com
Поставил x.Click.Type = DirectEventType.Load;
и у меня выходит тоже что и в самом начале

А IsUpload="true" не потерялся?

--

Daniil Veriga

unread,
Sep 9, 2014, 9:29:32 AM9/9/14
to ext...@googlegroups.com
System.NullReferenceException

А что именно null?

Viktor Sirchenko

unread,
Sep 9, 2014, 10:16:33 PM9/9/14
to ext...@googlegroups.com
В том то и прикол что не понятно, такая ошибка выходит если портал развернут на IIS, в студии такого нет, 
да и ошибка выходить даже когда в методе только 2 строчки, один из которых:
    return File(filePath, MIMEType, FileName);

вторник, 9 сентября 2014 г., 19:29:32 UTC+6 пользователь Daniil написал:

Daniil Veriga

unread,
Sep 10, 2014, 3:24:32 AM9/10/14
to ext...@googlegroups.com
Надо каким-то образом выловить, что же именно null:) Мне сложно что-то конкретное подсказать.

Viktor Sirchenko

unread,
Sep 10, 2014, 9:25:02 AM9/10/14
to ext...@googlegroups.com
Я сократил код метода до строчки return File(filePath, MIMEType, FileName);
остальное закоментил, и все равно выходит

Есть мысли что проблема с DirectEvent  именно в IIS, но весь остальной UI работает

среда, 10 сентября 2014 г., 1:24:32 UTC-6 пользователь Daniil написал:

Daniil Veriga

unread,
Sep 10, 2014, 10:27:00 AM9/10/14
to ext...@googlegroups.com
Я сократил код метода до строчки return File(filePath, MIMEType, FileName);
остальное закоментил, и все равно выходит

Видимо, проблема вылезает поглубже в MVC ASP.NET и/или IIS.


Есть мысли что проблема с DirectEvent  именно в IIS

Всякое может быть. Но в общем случае DirectEvent-ы c IIS нормально работают и, по идее, не слишком от IIS зависят.

Viktor Sirchenko

unread,
Sep 10, 2014, 10:50:12 AM9/10/14
to ext...@googlegroups.com
я тогда попробую вынести это в отдельный проект и протестить на нем, если все так же, то выложу его на растерзание

среда, 10 сентября 2014 г., 20:27:00 UTC+6 пользователь Daniil написал:

Viktor Sirchenko

unread,
Sep 10, 2014, 11:52:15 AM9/10/14
to ext...@googlegroups.com
блин, удалил все лишнее, оставил только форму с кнопкой и метод, выложил на IIS и все работает

среда, 10 сентября 2014 г., 20:50:12 UTC+6 пользователь Viktor Sirchenko написал:

Daniil Veriga

unread,
Sep 11, 2014, 3:29:46 AM9/11/14
to ext...@googlegroups.com
Надо удалять немножко шаг за шагом и каждый раз проверять, воспроизводится ли проблема.
Reply all
Reply to author
Forward
0 new messages