我需要从视图到控制器的id选择项目,然后将项目发送到另一个视图。 我的第一个视图,即我将项目的ID发送到编辑操作:
@foreach (var item in Model)
{
<tr>
<td>
@Html.Raw("<img style='width:80px; height:60px;' src=\"data:image/jpeg;base64,"
+ Convert.ToBase64String(item.Image) + "\" />")
</td>
<td>
@Html.ActionLink("Edit", "Edit", "Personal", new { id = item.Id }, null)
</td>
<td>
@Html.ActionLink("Remove", "Delete", "Personal", new { id = item.Id}, null)
</td>
</tr>
}
我的修改操作
public ActionResult Edit(int id)
{
ApplicationUser au = db.Users.Find(User.Identity.GetUserId());
Picture pic = new Picture();
foreach (var item in au.Pictures)
{
if (id == item.Id)
{
pic = item;
}
}
//Picture pic = new Picture { Id = id, Image = image};
return View(pic);
}
并查看等待项目
@model Dip_prj1.Models.Picture
@using Microsoft.AspNet.Identity
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Edit</title>
</head>
<body>
<div>
@Html.Raw("<img style='width:80px; height:60px;' src=\"data:image/jpeg;base64,"
+ Convert.ToBase64String(Model.Image) + "\" />")>
</div>
<div>
@Html.ActionLink("Вернуться к списку", "UserDetails", "Personal", new { id = User.Identity.GetUserId() }, null)
</div>
</body>
</html>
编辑控制器出现问题,导致我发送空字节数组的错误写入。请帮帮我。
答案 0 :(得分:0)
ApplicationUser au = db.Users.Include(t => t.Pictures).FirstOrDefault(t => (t.Id) == user);
This Include was clue