Warning I'm new to MVC and web stuff in general, I'm a long time C#/WPF programmer.
What I need to do is upload an excel document from the client, do some parsing of the document, show the parsed values in a form and the save all this to a database.
So I got the basic MVC form with the upload control and it does upload the file to the server. My question is how do I notify the controller that the upload is complete so I can parse the file and extract the data? I'm pretty sure that after I extract the data into my model I can create a simple form to display the results in a form and use the submit button to commit the changes to the database.
I've tried getting client side alerts and that is not working either
UploadWorkbook.cshtml
@using Infragistics.Web.Mvc @using Infragistics.Web.Mvc @using OneOfficeWeb.Models @{ ViewBag.Title = "UploadWorkbook"; } <script type="text/javascript"> $(window).load(function () { $("#igUpload").bind({ iguploadonerror: function (e, args) { alert(args.errorMessage); } }); $("igUpload1").bind({ fileUploaded: function(e, args) { alert(args.filePath); } }); }); </script> <div class="sampleContents"> <div class="sample-container"> <p>Upload workbook</p> @using (Html.BeginForm("Upload", "UploadWorkbook", FormMethod.Post, new { @encType = "multipart/form-data" })) { @(Html.Infragistics().Upload() .ID("igUpload1") .ControlId("uploadControl") .Mode(UploadMode.Single) .AutoStartUpload(true) .AllowedExtensions(new List<string> { "xls", "xlsx" }) .ProgressUrl(Url.Content("~/IGUploadStatusHandler.ashx")) .ControlId("serverID1") .Render()) } <div id="error-message" style="color: #FF0000; font-weight: bold;"></div> </div> </div>
Web.config
...
<httpHandlers> <add verb="GET" type="Infragistics.Web.Mvc.UploadStatusHandler" path="IGUploadStatusHandler.ashx" /> </httpHandlers> <httpModules> <add name="IGUploadModule" type="Infragistics.Web.Mvc.UploadModule" /> </httpModules> </system.web> _Layout.cshtml ... <link type="text/css" href="@Url.Content("~/Styles/css/themes/infragistics/infragistics.theme.css")" rel="stylesheet" /> <link type="text/css" href="@Url.Content("~/Styles/css/structure/infragistics.css")" rel="stylesheet" /> <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")"></script> <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")"></script>
<httpHandlers> <add verb="GET" type="Infragistics.Web.Mvc.UploadStatusHandler" path="IGUploadStatusHandler.ashx" /> </httpHandlers> <httpModules> <add name="IGUploadModule" type="Infragistics.Web.Mvc.UploadModule" /> </httpModules> </system.web>
_Layout.cshtml
<link type="text/css" href="@Url.Content("~/Styles/css/themes/infragistics/infragistics.theme.css")" rel="stylesheet" /> <link type="text/css" href="@Url.Content("~/Styles/css/structure/infragistics.css")" rel="stylesheet" /> <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")"></script> <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")"></script>
Still not getting it, I'm trying to catch the event and nothing seems to work. Is it possible to get a sample?
@using Infragistics.Web.Mvc @using Infragistics.Web.Mvc @using OneOfficeWeb.Models @{ ViewBag.Title = "UploadWorkbook"; } <script type="text/javascript" src="~/Scripts/jquery-1.4.4.min.js"></script> <script type="text/javascript" src="~/Scripts/jquery-ui.min.js"></script> <script type="text/javascript" src="~/Scripts/IG/infragistics.js"></script> <script type="text/javascript" language="javascript"> $(document).delegate(".igUpload1", 'iguploadfileuploaded', function (e, args) { alert("hi"); }); $(".igUpload1").igUpload({ fileUploaded: function (evt, ui) { alert("hi"); } }); </script> <h3>Upload workbook</h3> <div> @(Html.Infragistics().Upload() .ID("igUpload1") .ControlId("uploadControl") .Mode(UploadMode.Single) .AutoStartUpload(true) .AllowedExtensions(new List<string> { "xls", "xlsx" }) .ProgressUrl(Url.Content("~/IGUploadStatusHandler.ashx")) .ControlId("serverID1") .Render()) </div>
Hi,
here is a small sample. Let me know if it was helpful.
Thank you
Perfect, thank you