我有一个包含我所有项目的视图,我希望只有超级管理员能够编辑我在我的超级管理员控制器中调用 editProjects 操作,但我想在项目下拥有编辑项目视图。如何获取我的特定项目以供查看。这是我的代码
查看"项目"视图
@foreach (var item in Model)
{
<tbody>
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProjectId)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.NatureOfIndustry)
</td>
<td>
@Html.ActionLink("Edit", "EditProject", "SuperAdmin", new { id = item.ProjectId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ProjectId })
</td>
</tr>
</tbody> //Super admin action public ActionResult EditProject(int id)
{
if (id < 0)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var project = context.Projects.Where(p =>
p.ProjectId.Equals(id)).FirstOrDefault();
if (project == null)
{
return HttpNotFound();
}
return View("~/Views/Projects/EditProject.cshtml",new ProjectUpdateModel()
{
ProjectId = project.ProjectId,
ProjectName = project.ProjectName,
ProjectCode = project.ProjectCode,
NatureOfIndustry = project.NatureOfIndustry
});
}
我想通了我在操作链接中缺少"空">
@Html.ActionLink("Edit", "EditProject", "SuperAdmin", new { id = item.ProjectId }, null) |
现在它工作了