Das ist mein AnsichtsmodellWie kann ich cshtml für meine bearbeiten Ansichtsmodell machen
namespace CRUD2.ViewModel
{
public class CostVM
{
public int id { get; set;}
public string nama { get; set; }
public string alamat { get; set; }
public string jenis { get; set; }
public informasi informasi { get; set; }
public iseng iseng { get; set; }
}
}
Das ist mein Index.cshtml
@model IEnumerable<CRUD2.ViewModel.CostVM>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<table cellspacing="2px;">
<tr>
<th>Nama</th>
<th>Alamat</th>
<th>Jenis</th>
<th>Action</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.informasi.nama</td>
<td>@item.informasi.alamat</td>
<td>@item.iseng.jenis</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.informasi.id }) |
@Html.ActionLink("Back to List", "Index")
</td>
</tr>
}
</table>
</body>
</html>
und das ist mein Controler (Bearbeiten und Index)
namespace CRUD2.Controllers
{
public ActionResult Edit(int id = 0)
{
var costumerlist = from cust in db.informasis
join ord in db.isengs
on cust.id equals ord.id
where cust.id == id
select new { cust.nama, cust.alamat, cust.jk, cust.kelas, ord.jenis };
return View(costumerlist.FirstOrDefault());
}
}
}
Wie kann ich meine Edit.cshtml machen? Ich verstehe nicht, wie das zu machen, ich habe keine Ahnung, und wenn ich irgendwelche Fehler in meinem Code haben, bitte es beheben .. Danke
Sorry für mein schlechtes Englisch ..
Bitte sehen Sie sich an: https://weblogs.asp.net/scottgu/asp-net-mvc-3-new-model-directive-support-in-razer Es sieht so aus als ob Sie einen anonymen Typ erstellen, Die Ansicht erwartet jedoch eine Liste von CostVM. Außerdem muss der Name Ihrer Ansicht nach dem Namen der Methode übereinstimmen. Ihre Methode heißt also "edit", also muss Ihre Ansicht auch "edit.cshtml" heißen. –