TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mahmudur rifat
NA
33
13.3k
data pass controller to view
Jul 18 2016 12:58 AM
mvc project 4. i want list pass controller to view and show my combo box
below in controller code:
using Excel;
using Office_Project.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MExcel = Microsoft.Office.Interop.Excel;
namespace Office_Project.Controllers
{
public class FileController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Upload()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Upload(HttpPostedFileBase upload)
{
List<SEfile> sefile = new List<SEfile>();
if (ModelState.IsValid)
{
if (upload != null && upload.ContentLength > 0)
{
Stream stream = upload.InputStream;
IExcelDataReader reader = null;
if (upload.FileName.EndsWith(".xls"))
{
reader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else if (upload.FileName.EndsWith(".xlsx"))
{
reader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else
{
ModelState.AddModelError("File", "This file format is not supported");
return View();
}
reader.IsFirstRowAsColumnNames = true;
DataSet result = reader.AsDataSet();
//return View(result.Tables[0]);
while (reader.Read())
{
string invoice = reader.GetString(0);
DateTime dateinvoice = reader.GetDateTime(1);
DateTime datepayment = reader.GetDateTime(2);
string sender = reader.GetString(3);
string benificiary = reader.GetString(4);
string accountNumber = reader.GetString(5);
string bankBranch = reader.GetString(6);
string bankName = reader.GetString(7);
string city = reader.GetString(8);
int reference = reader.GetInt32(9);
string pin = reader.GetString(10);
string cashier = reader.GetString(11);
decimal totalPayDollar = reader.GetDecimal(12);
decimal totalPayLocal = reader.GetDecimal(13);
string branch = reader.GetString(14);
int senderPhone = reader.GetInt32(15);
int receiverPhone = reader.GetInt32(16);
SEfile filelist = new SEfile();
filelist.Invoice = invoice;
filelist.DateInvoice = dateinvoice;
filelist.DatePayment = datepayment;
filelist.Sender = sender;
filelist.Benificiary = benificiary;
filelist.AccountNumber = accountNumber;
filelist.BankBranch = bankBranch;
filelist.BankName = bankName;
filelist.City = city;
filelist.Reference = reference;
filelist.Pin = pin;
filelist.Cashier = cashier;
filelist.TotalPayDollar = totalPayDollar;
filelist.TotalPayLocal = totalPayLocal;
filelist.Branch = branch;
filelist.SenderPhone = senderPhone;
filelist.ReceiverPhone = receiverPhone;
sefile.Add(filelist);
ViewBag.MovieType = sefile;
return View();
}
reader.Close();
}
else
{
ModelState.AddModelError("File", "Please Upload Your file");
}
}
return View("Upload");
}
}
}
Reply
Answers (
3
)
Error SignTool.exe
Store object after login