Hỏi đáp

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

lấy dữ liệu từ database asp.net mvc

13:20 14-08-2017 5.130 lượt xem 4 bình luận 14:31 14-08-2017

code của em

model:
 

public class CatagoryViewModel
    {
        public int ct_id { get; set; }
        public string ct_name { get; set; }
        public int ct_status { get; set; }
    }

public List<Catagory> ListAllCatagory()
        {
            return db.Catagories.Where(x => x.ct_status == 1).ToList();
        }

controller:

public ActionResult Index()
        {
            return View();
            ShowCatagory();
        }
public void ShowCatagory()
        {
            var ctDao = new catagoryDao();
            List<SelectListItem> itemsCT = new SelectList(ctDao.ListAllCatagory()).ToList();
        }

View:

@model List<FlashSale.Models.CatagoryViewModel>

@foreach (var item in Model)
                        {
                            <li>
                                <a href="/redirect?Id=6U%2fmjnomkcLNhYuCvRy2A6k%2fY3%2fRAGjRPvqSuAevvn0%3d"
                                    @item.ct_name
                                </a>
                            </li>
                        }

 

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
K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 14:31 14-08-2017

thấy logic chạy búa xua. cứ return View(db.Category.ToList());

xong

K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 14:03 14-08-2017

đồng thời mình k rõ câu hỏi của bạn là gì

K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 14:03 14-08-2017

bạn học asp.net mvc ở đâu z. + thêm retun rồi thì code sau đó đâu có sài dc

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