Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Asp.net MVC: cách lấy dữ liệu từ datatable trong controller đổ ra view

8 năm trước 5.049 lượt xem 8 bình luận 8 năm trước

Chào mọi người, em gặp phải 1 vấn đề như thế này:

-Trong controller e đã get được dữ liệu đổ vào 1 DataTable

-Giờ muốn duyệt được dữ liệu trong DataTable đó để đổ ra View thì làm sao ạ
 

//Controller:

View:


 

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
phamvanhieu.th2006 đã bình luận 8 năm trước

Bạn truy cập vào bài viết này để xem nhé... Chắc chắn bạn sẽ hiểu. Sử dụng Linq truy xuất CRUD từ SQL

 

N T đã bình luận 8 năm trước

Muốn cho View hiểu Model từ control truyền sang thì Return View(model). Trước đó, bạn phải chuyển Model Dal sang Model View thì View nó mới hiểu được nhé, như code của bạn thì Model View của bạn chưa có gì nên nó sẽ ko hiển thị.

K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 8 năm trước
public ActionResult Index(ReportMerchantSearchForm searchForm, string command)
        {
            if (command.Equals("Search"))
            {
                var model = new ReportMerchantViewModel();
                string getMerchantPurse = "";
                var mcDao = new mc_merchantsDao();
                var merchantlist = mcDao.ListAll();
                foreach (var item in merchantlist)
                {
                    getMerchantPurse += "'" + item.merchant_purse + "',";
                }
                getMerchantPurse = getMerchantPurse.Substring(0, getMerchantPurse.Length - 1);
                var wm_devbackend_operationsDao = new wm_devbackend_operationsDao();
                DataTable historyMerchant = wm_devbackend_operationsDao.getHistoryMerchant(getMerchantPurse, CommonConstants.CONNECTION_STRING_WALLET_DB);
            //    DataTable dt = new DataTable();
             //   return View(historyMerchant);    
                return View(model);
            }
            return View();

Return View(model); thôi bạn

Câu hỏi mới nhất