我有一个包含所有项目的视图,我只希望superAdmin能够进行editProjects,而我要在SuperAdmin控制器中调用editProjects操作,但是希望在项目下拥有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
});
}
答案 0 :(得分:0)
我知道了 我在动作链接中缺少“ NULL”
@Html.ActionLink("Edit", "EditProject", "SuperAdmin", new { id = item.ProjectId }, null) |
现在可以使用