How to Pass a Dataset from Controller to View in MVC

buyzithromaxxxx

New Member
Actually my Scenario is :Importing data from excel to db.here i am passing the dataset from controller to view through viewbag.now i need to bind that dataset to a gridview in POPUP.In my View, a Button is present and on button click ,popup will appear.but while i am returning view from controller to view,it is showing button but not the popup.In my View :\[code\]<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"><h2>ImportExcel</h2><div align="center"> <% Html.DevExpress().Button(settings =>{ settings.Name = "btn_Import"; settings.Text = "Import Excel Sheet"; settings.UseSubmitBehavior = true;}).Render(); %></div><%: Html.DevExpress().PopupControl(settings =>{ settings.Name = "pcModalMode"; settings.Width = 400; settings.AllowDragging = true; settings.CloseAction = CloseAction.CloseButton; settings.PopupElementID = "btn_Import"; settings.PopupAnimationType = AnimationType.None; settings.HeaderText = "Upload Email Addresses (XLS/XLSX)"; settings.Modal = true; settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter; settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter; settings.SetContent(() => { using (Html.BeginForm("ImportExcel", "PopUp", FormMethod.Post, new { enctype = "multipart/form-data" })) { Html.Hidden("ID"); ViewContext.Writer.Write("<div class=\"line\">"); Html.DevExpress().Label( labelSettings => { labelSettings.Text = "Choose Your File:"; } ) .Render(); Html.DevExpress().UploadControl(Usettings => { Usettings.Name = "ImportData"; Usettings.CallbackRouteValues = new { Controller = "PopUp", Action = "Upload" }; Usettings.Width = Unit.Pixel(380); Usettings.NullText = "Click here to browse files..."; Usettings.ShowProgressPanel = true; }).Render(); ViewContext.Writer.Write( "</div><div class=\"line\">"); Html.DevExpress().Button( buttonSettings => { buttonSettings.Name = "btnUpload"; //buttonSettings.ControlStyle.CssClass = "button"; //buttonSettings.Width = 80; buttonSettings.Text = "Upload"; buttonSettings.UseSubmitBehavior = true; } ) .Render(); Html.DevExpress().Button( buttonSettings => { buttonSettings.Name = "btnCancel"; //buttonSettings.ControlStyle.CssClass = "button"; buttonSettings.Width = 80; buttonSettings.Text = "Cancel"; buttonSettings.ClientSideEvents.Click = "function(s, e){ pcModalMode.Hide(); }"; } ) .Render(); ViewContext.Writer.Write("</div><b class=\"Clear\"></b>"); DataSet ds = (DataSet)ViewBag.imp; } }); settings.ClientSideEvents.CloseUp = "function(s, e){ ASPxClientEdit.ClearEditorsInContainer(null, '', true); }";}).GetHtml()%>\[/code\]and My controller is :\[code\] [AcceptVerbs(HttpVerbs.Post)] public ActionResult ImportExcel(FormCollection form) { UploadedFile[] files = UploadControlExtension.GetUploadedFiles("ImportData"); StringBuilder strValidations = new StringBuilder(string.Empty); try { if (files[0].ContentLength > 0) { string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(files[0].FileName)); files[0].SaveAs(filePath); DataSet ds = new DataSet(); string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("../Uploads/") + files[0].FileName + ";Extended Properties=Excel 12.0"; using (OleDbConnection conn = new OleDbConnection(ConnectionString)) { conn.Open(); using (DataTable dtExcelSchema = conn.GetSchema("Tables")) { string sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString(); string query = "SELECT * FROM [" + sheetName + "]"; OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn); adapter.Fill(ds1, "Items"); ViewData["Mydataset"] = ds1; ViewBag.imp = ds1; ViewBag.text = "FIrst"; } } } } catch (Exception ex) { ex.Message.ToString(); } return View(); }\[/code\]
 
Back
Top