Controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[HttpGet] public ActionResult Index() { #region OgretmenData List<Ogretmen> modelOgretmen = new List<Ogretmen>(); modelOgretmen.Add(new Ogretmen { Id = 1, Ad = "ahmet", Soyad = "Başdan", Bolum = "Bilgisayar" }); modelOgretmen.Add(new Ogretmen { Id = 1, Ad = "mehmet", Soyad = "yılmaz", Bolum = "Türkçe" }); modelOgretmen.Add(new Ogretmen { Id = 1, Ad = "ali", Soyad = "bulut", Bolum = "Resim" }); modelOgretmen.Add(new Ogretmen { Id = 1, Ad = "haydar", Soyad = "koç", Bolum = "Müzik" }); modelOgretmen.Add(new Ogretmen { Id = 1, Ad = "engin", Soyad = "su", Bolum = "Geometri" }); #endregion return View(Tuple.Create<List<Ogretmen>, Ogrenci>(modelOgretmen, new Ogrenci())); } |
1 2 3 4 5 |
[HttpPost] public ActionResult Index([Bind(Prefix = "Item2")]Ogrenci Model1) { return View(Tuple.Create<List<Ogretmen>,Ogrenci>(new List<Ogretmen>(),new Ogrenci())); } |
View
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
@using dataTableMVC.class_ @model Tuple<List<Ogretmen>,Ogrenci> @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Tuple Sınfı</title> </head> <body> <h2>Öğretmen Tablosu</h2> <table border="1"> <tr> <td>Ad</td> <td>Soyad</td> <td>Bölüm</td> </tr> @foreach (var item in Model.Item1) { <tr> <td>@item.Ad</td> <td>@item.Soyad</td> <td>@item.Bolum</td> </tr> } </table> <h2>Öğrenci Ekle</h2> @using (Html.BeginForm("Index", "Tuple", FormMethod.Post)) { <label>Ad</label> <br /> @Html.TextBoxFor(x=>x.Item2.Ad) <br /> <label>Soyad</label> <br /> @Html.TextBoxFor(x => x.Item2.Soyad) <br /> <label>Sınıf</label> <br /> @Html.TextBoxFor(x => x.Item2.Sinif) <br /> <br /> <button type="submit">Gönder</button> } </body> </html> |
Class
1 2 3 4 5 6 |
public class Ogrenci { public string Ad { get; set; } public string Soyad { get; set; } public string Sinif { get; set; } } |
1 2 3 4 5 6 7 |
public class Ogretmen { public int Id { get; set; } public string Ad { get; set; } public string Soyad { get; set; } public string Bolum { get; set; } } |