[CLOSED] [MVC] FileUpload in MVC

  1. #1

    [CLOSED] [MVC] FileUpload in MVC

    Hi, Could you give me an axample for using FileUpload in MVC?
    Html.X().FormPanel()
                                                                 .Border(false)
                                                                 .ID("UploadForm")
                                                                 .Items(itm =>
                                                                            {
                                                                                itm.Add(Html.X().TextField().FieldLabel("Name"));
                                                                                itm.Add(Html.X().FileUploadField().FieldLabel("Select new document").Icon(Icon.Attach));
                                                                                itm.Add(Html.X().TextField().FieldLabel("Description"));
                                                                            })
                                                                 .Listeners(l => l.ValidityChange.Handler = "#{SaveButton}.setDisabled(!valid);")
                                                                 .Buttons(btn =>
                                                                              {
                                                                                  btn.Add(Html.X().Button().ID("SaveButton").Text("Upload").Disable(true)
                                                                                              .OnClientClick("doUpload();")
                                                                                              .DirectEvents(d =>
                                                                                                                {
                                                                                                                    d.Click.Before = "if (!#{UploadForm}.getForm().isValid()) { return false; } Ext.Msg.wait('Uploading ...', 'Uploading');";
                                                                                                                    d.Click.Failure = "Ext.Msg.show({ title : 'Error',msg : 'Error during uploading',minWidth: 200,modal   : true,icon    : Ext.Msg.ERROR,buttons : Ext.Msg.OK });";
                                                                                                                }));
                                                                                  btn.Add(Html.X().Button().Text("Reset").Listeners(ls => ls.Click.Handler = "#{UploadForm}.getForm().reset();"));
                                                                              }))
    What must I add to this view and the controller?
    Last edited by Daniil; Jun 08, 2012 at 2:22 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Example View
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.Net.MVC v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        
        <ext:FormPanel runat="server" Width="300" Url="/Test/Submit">
            <Items>
                <ext:FileUploadField 
                    runat="server" 
                    FieldLabel="FileUploadField" 
                    AnchorHorizontal="100%">
                    <Listeners>
                        <Change Handler="this.ownerCt.submit();" />
                    </Listeners>
                </ext:FileUploadField>
            </Items>
        </ext:FormPanel>
    </body>
    </html>
    Example Controller Action
    public ActionResult Submit()
    {
        HttpPostedFileBase file = Request.Files[0];
        object r = new
        {
            success = true,
            name = Request.Files[0].FileName
        };
        return Content(string.Format("<textarea>{0}</textarea>", JSON.Serialize(r))); ;
    }
    Last edited by Daniil; Mar 27, 2013 at 1:37 PM.
  3. #3
    A new example of upload. Demonstrates how to use a FormPanelResult and pass parameters.

    Example View
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.Net.MVC v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:FormPanel runat="server" Width="300" Url="/Aspx/Submit">
            <Items>
                <ext:FileUploadField runat="server" FieldLabel="FileUploadField" AnchorHorizontal="100%">
                    <Listeners>
                        <Change Handler="this.up('form').submit({
                                params: {
                                    testParam: 'testValue'
                                }
                            });" />
                    </Listeners>
                </ext:FileUploadField>
            </Items>
        </ext:FormPanel>
    </body>
    </html>
    Example Action
    public FormPanelResult Submit(string testParam)
    {
        FormPanelResult r = new FormPanelResult();
        r.IsUpload = true;
        r.Success = true;
        string msg = Request.Files[0].FileName + "<br/>testParam: " + testParam;
    
        X.Msg.Alert("Uploaded", msg).Show();
    
        return r;
    }
  4. #4
    @Dannil thanks. Second example with parameters works perfect.

    If some one needs convert received File to by Array this post can help it:
    http://stackoverflow.com/questions/1...-get-its-bytes
    Last edited by equiman; Jan 20, 2015 at 9:21 PM.
  5. #5
    I'm trying found the way... but i'm lost.

    Where is the place to show Mask and how receive response when is success or failure?
  6. #6
    You could show a mask just before a .submit() call.

    As for success and failure, there are respective handlers you could pass via a config object of a .submit(config) call.

    See also
    http://docs.sencha.com/extjs/4.2.1/#...-method-submit
  7. #7
    Now I see the light... it's like an Ext.net.DirectMethod.request
    Thanks!!!! works excellent.

    Finally I'm not implement a mask:
    Ext.Msg.wait('Uploading file...', '');
    Then... when finish (to hide it):
    Ext.MessageBox.hide();
    In this cases... I think it's more useful wait message than a mask!
    Last edited by equiman; Jan 27, 2015 at 6:21 PM.

Similar Threads

  1. [CLOSED] [#92] FileUpload
    By Timothy in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Jan 16, 2013, 3:44 AM
  2. [CLOSED] Please help me with a fileupload question
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 15, 2012, 6:41 AM
  3. [CLOSED] [1.0] FileUpload and Directory
    By FVNoel in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 07, 2011, 7:30 AM
  4. [CLOSED] [1.0] FileUpload FileName IE - FF
    By methode in forum 1.x Legacy Premium Help
    Replies: 15
    Last Post: Feb 23, 2011, 1:51 PM
  5. bug in fileupload
    By pablisho in forum 1.x Help
    Replies: 0
    Last Post: Jul 01, 2009, 10:55 AM

Tags for this Thread

Posting Permissions