Trong truy vấn này tôi có 3 bản ghi (int- (telefon = d.telefon), thập phân- (pesel = d.pesel), thập phân- (nip = d.nip)) một bản ghi khác là chuỗi .Không thể chuyển đổi hoàn toàn loại 'int?' đến 'int'
public ActionResult detail(int LoginID)
{
var user = (from d in baza.uzytkowniks
where LoginID == d.LoginID
select new uzytkownikModel {
imie = d.imie,
nazwisko = d.nazwisko,
telefon = d.telefon,
pesel = d.pesel,
nip = d.nip,
email = d.email,
adres_zamieszkania = d.adres_zamieszkania}).ToList();
ViewBag.daneuser = user;
return View();
}
Và tôi có lỗi:
Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?)
và hai khác lỗi với 'thập phân?' thay vào đó 'int?'.
mẫu:
public class uzytkownikModel
{
[Required]
public string imie { get; set; }
[Required]
public string nazwisko { get; set; }
public decimal pesel { get; set; }
public decimal nip { get; set; }
public string adres_zamieszkania { get; set; }
public int telefon { get; set; }
public string email { get; set; }
}
Chỉ imie và nazwisko được nonnullable, phần còn lại đã cho phép null
///////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// //////////
Hiện đang hoạt động. Tôi thay đổi trong mô hình:
decimal to decimal?
và
int to int?
Cảm ơn mọi người giúp đỡ
lý do bạn không hiển thị lớp uzytkownikModel? có thể bạn nhận được lỗi đó bởi các trường hoặc thuộc tính không khớp với cùng loại với các giá trị của bạn. –
bạn có thể đăng định nghĩa kiểu 'd' không? – JohnD
Tôi đã thêm mã khác – user1031034