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>
}
thấy logic chạy búa xua. cứ return View(db.Category.ToList());
xong
đồng thời mình k rõ câu hỏi của bạn là gì
bạn học asp.net mvc ở đâu z. + thêm retun rồi thì code sau đó đâu có sài dc