Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1

    Làm sao để View và add dư liệu sử dụng Linq to SQL trong cùng 1 view

    Hiện giờ mình đang mắc vấn đề này mong mọi người giúp đỡ........

    và mình cần hỏi các vấn đề liên quan :
    1, phải tạo model như thế nào 1 hay 2 model cho view và add khác nhau hay dùng chung 1 model

    đây là đoạn code model của mục view của mình

    Mã:
    public string TourName { get; set; }
            public DateTime DepartureDay { get; set; }
            public string DeparturePosition { get; set; }
            public int AvailableRoom { get; set; }
    
            public BookingViewModels(string tourname, DateTime departureday,string departureposition, int availableroom)
            {
                this.TourName = tourname; this.DepartureDay = departureday; this.DeparturePosition = departureposition; this.AvailableRoom = availableroom;
            }
    2,bên phần controller thì nên làm như thế nào
    còn đây là phần controller của mục view của mình
    Mã:
    public ActionResult TourBooking(string strID, Booking addbooking)
            {
                var id_tour = (from db in _data.Tours
                               //join db2 in _data.Bookings on db.ID_Tour equals db2.ID_Tour
                               where db.ID_Tour == strID 
                               //&& db2.ID_Tour == db.ID_Tour
                               select new
                               {
                                   db.TourName,
                                   db.DepartureDay,
                                   db.DeparturePosition,
                                   db.AvailableRoom,
                               }).FirstOrDefault();
                var view_tour = new BookingViewModels(id_tour.TourName, Convert.ToDateTime(id_tour.DepartureDay), id_tour.DeparturePosition, Convert.ToInt32(id_tour.AvailableRoom));
                return View(view_tour);
            }
    còn đây là phần model các thuộc tính cần Add của bảng thứ 2
    Mã:
    public class BookingAddModels
        {
            public string ID_Booking { get; set; }
            public string CompanyName { get; set; }
            public string OrdererName { get; set; }
            public string IDcardNo { get; set; }
            public string Address { get; set; }
            public int PhoneNumber { get; set; }
            public string Email { get; set; }
            public string TaxCode { get; set; }
            public int TotalOfTourist { get; set; }
            public int Adult { get; set; }
            public int Children { get; set; }
            public int Baby { get; set; }
            public DateTime BookingDay { get; set; }
            public DateTime PaymentDay { get; set; }
            public decimal TotalOfCost { get; set; }
            public string PaymentMethod { get; set; }
            public string ID_Tour { get; set; }
        }
    mong mọi người giúp đỡ đề án sắp đến hạn T.T ko bit bao giờ xong T.T...........

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    bạn hỏi chả hiểu gì cả

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •