所以我创建了一个包含它们的视图模型:
public class TwoPageViewModel
{
public IEnumerable<Leepio.Models.Project> Model1 { get; set; }
public IndexViewModel Model2 { get; set; }
}
在Views / Manage / Index.cshtml中我有这个:
@using Leepio.Models
@using Microsoft.AspNet.Identity
@model Leepio.Models.TwoPageViewModel
@{
ViewBag.Title = "Manage";
}
<h2>@ViewBag.Title.</h2>
<p class="text-success">@ViewBag.StatusMessage</p>
<div>
<h4>Change your account settings</h4>
<hr />
<dl class="dl-horizontal">
<dt>Phone Number:</dt>
<dd>
@(Model.Model2.PhoneNumber ?? "None")
[
@if (Model.Model2.PhoneNumber != null)
{
@Html.ActionLink("Change", "AddPhoneNumber")
}
else
{
@Html.ActionLink("Add", "AddPhoneNumber")
}
]
</dd>
<dt>Email</dt>
<dd>
@(Model.Model2.Email ?? "None")
[
@if (Model.Model2.Email != null)
{
@Html.ActionLink("Change", "ChangeEmail")
}
else
{
@Html.ActionLink("Add", "ChangeEmail")
}
]
</dd>
@if (Model.Model2.FirstName != null)
{
<dt>First Name</dt>
<dd>
@(Model.Model2.FirstName ?? "None")
[
@if (Model.Model2.FirstName != null)
{
@Html.ActionLink("Change", "ChangeFirstName")
}
else
{
@Html.ActionLink("Add", "ChangeFirstName")
}
]
</dd>
}
@if (Model.Model2.LastName != null)
{
<dt>Last Name</dt>
<dd>
@(Model.Model2.LastName ?? "None")
[
@if (Model.Model2.LastName != null)
{
@Html.ActionLink("Change", "ChangeLastName")
}
else
{
@Html.ActionLink("Add", "ChangeLastName")
}
]
</dd>
}
<dt>City</dt>
<dd>
@(Model.Model2.City ?? "None")
[
@if (Model.Model2.City != null)
{
@Html.ActionLink("Change", "ChangeCity")
}
else
{
@Html.ActionLink("Add", "ChangeCity")
}
]
</dd>
@if (Model.Model2.CompanyName != null)
{
<dt>CompanyName</dt>
<dd>
@(Model.Model2.CompanyName ?? "None")
[
@if (Model.Model2.CompanyName != null)
{
@Html.ActionLink("Change", "ChangeUserName")
}
else
{
@Html.ActionLink("Add", "ChangeUserName")
}
]
</dd>
}
<dt>ZipCode</dt>
<dd>
@(Model.Model2.ZipCode ?? "None")
[
@if (Model.Model2.ZipCode != null)
{
@Html.ActionLink("Change", "ChangeZipCode")
}
else
{
@Html.ActionLink("Add", "ChangeZipCode")
}
]
</dd>
@if (Model.Model2.Region != null)
{
<dt>Region</dt>
<dd>
@(Model.Model2.Region ?? "None")
[
@if (Model.Model2.Region != null)
{
@Html.ActionLink("Change", "ChangeRegion")
}
else
{
@Html.ActionLink("Add", "ChangeRegion")
}
]
</dd>
}
@if (Model.Model2.NrEmployees != 0)
{
<dt>NrEmployees</dt>
<dd>
@(Model.Model2.NrEmployees)
[
@if (Model.Model2.NrEmployees != 0)
{
@Html.ActionLink("Change", "ChangeNrEmployees")
}
else
{
@Html.ActionLink("Add", "ChangeNrEmployees")
}
]
</dd>
}
@if (Model.Model2.WorkField != null)
{
<dt>WorkField</dt>
<dd>
@(Model.Model2.WorkField ?? "None")
[
@if (Model.Model2.WorkField != null)
{
@Html.ActionLink("Change", "ChangeWorkField")
}
else
{
@Html.ActionLink("Add", "ChangeWorkField")
}
]
</dd>
}
<dt>Language</dt>
<dd>
@(Model.Model2.Language ?? "None")
[
@if (Model.Model2.Language != null)
{
@Html.ActionLink("Change", "ChangeLanguage")
}
else
{
@Html.ActionLink("Add", "ChangeLanguage")
}
]
</dd>
@if (Model.Model2.University != null)
{
<dt>University</dt>
<dd>
@(Model.Model2.University ?? "None")
[
@if (Model.Model2.University != null)
{
@Html.ActionLink("Change", "ChangeUniversity")
}
else
{
@Html.ActionLink("Add", "ChangeUniversity")
}
]
</dd>
}
@if (Model.Model2.StudyProgramme != null)
{
<dt>StudyProgramme</dt>
<dd>
@(Model.Model2.StudyProgramme ?? "None")
[
@if (Model.Model2.StudyProgramme != null)
{
@Html.ActionLink("Change", "ChangeStudyProgramme")
}
else
{
@Html.ActionLink("Add", "ChangeStudyProgramme")
}
]
</dd>
}
@if (Model.Model2.Semester != 0)
{
<dt>Semester</dt>
<dd>
@(Model.Model2.Semester)
[
@if (Model.Model2.Semester != 0)
{
@Html.ActionLink("Change", "ChangeSemester")
}
else
{
@Html.ActionLink("Add", "ChangeSemester")
}
]
</dd>
}
@if (Model.Model2.GraduationDate != null)
{
<dt>GraduationDate</dt>
<dd>
@(Model.Model2.GraduationDate ?? "None")
[
@if (Model.Model2.GraduationDate != null)
{
@Html.ActionLink("Change", "ChangeGraduationDate")
}
else
{
@Html.ActionLink("Add", "ChangeGraduationDate")
}
]
</dd>
}
<dt>Description</dt>
<dd>
@(Model.Model2.Description ?? "None")
[
@if (Model.Model2.Description != null)
{
@Html.ActionLink("Change", "ChangeDescription")
}
else
{
@Html.ActionLink("Add", "ChangeDescription")
}
]
</dd>
@if (Model.Model2.Skills != null)
{
<dt>Skills</dt>
<dd>
@(Model.Model2.Skills ?? "None")
[
@if (Model.Model2.Skills != null)
{
@Html.ActionLink("Change", "ChangeSkills")
}
else
{
@Html.ActionLink("Add", "ChangeSkills")
}
]
</dd>
}
@if (@Model.Model2.Experience != null)
{
<dt>Experience</dt>
<dd>
@(Model.Model2.Experience ?? "None")
[
@if (Model.Model2.Experience != null)
{
@Html.ActionLink("Change", "ChangeExperience")
}
else
{
@Html.ActionLink("Add", "ChangeExperience")
}
]
</dd>
}
@if (Model.Model2.Website != null)
{
<dt>Website</dt>
<dd>
@(Model.Model2.Website ?? "None")
[
@if (Model.Model2.Website != null)
{
@Html.ActionLink("Change", "ChangeWebsite")
}
else
{
@Html.ActionLink("Add", "ChangeWebsite")
}
]
</dd>
}
<dt>Password:</dt>
<dd>
[
@if (Model.Model2.HasPassword)
{
@Html.ActionLink("Change your password", "ChangePassword")
}
else
{
@Html.ActionLink("Create", "SetPassword")
}
]
</dd>
</dl>
<table class="table">
<tr>
<th>
@Html.ActionLink("Title", "Index", new { SortOrder = (ViewBag.SortOrder == null ? "Asc" : (ViewBag.SortOrder == "Asc" ? "Desc" : "Asc")), SortBy = "Title" })
</th>
<th>
@Html.ActionLink("Application Deadline", "Index", new { SortOrder = (ViewBag.SortOrder == null ? "Asc" : (ViewBag.SortOrder == "Asc" ? "Desc" : "Asc")), SortBy = "ApplicationDeadline" }) <br />
@Html.ActionLink("Hourly Rate (DKK)", "Index", new { SortOrder = (ViewBag.SortOrder == null ? "Asc" : (ViewBag.SortOrder == "Asc" ? "Desc" : "Asc")), SortBy = "HourlyRate" })
</th>
<th>
@Html.ActionLink("Skill requirements", "Index", new { SortOrder = (ViewBag.SortOrder == null ? "Asc" : (ViewBag.SortOrder == "Asc" ? "Desc" : "Asc")), SortBy = "RequiredSkills" })
</th>
</tr>
@foreach (var item in Model.Model1)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ApplicationDeadline)<br />
@Html.DisplayFor(modelItem => item.HourlyRate)
</td>
<td>
@Html.DisplayFor(modelItem => item.RequiredSkills)
</td>
<td>
@if (item.UserId == User.Identity.GetUserId())
{
@Html.ActionLink("Edit", "Edit", "Projects", new { id = item.ProjectId }, null)
@Html.ActionLink("Delete", "Delete", "Projects", new { id = item.ProjectId }, null)
}
@Html.ActionLink("Details", "Details", "Projects", new { id = item.ProjectId }, null) |
</td>
</tr>
}
</table>
</div>
此处未找到“编辑”,“删除”和“详细信息”操作。它们位于Controllers \ ProjectsController.cs
中如何引用要知道的文件来执行此控制器的操作?有一些我缺少的东西
答案 0 :(得分:2)
您需要提供控制器名称并传递所需的参数。用这个:
@Html.ActionLink("Edit", "Edit", "Projects", new { id = item.ProjectId }, null)
@Html.ActionLink("Delete", "Delete", "Projects", new { id = item.ProjectId }, null)
@Html.ActionLink("Details", "Details", "Projects", new { id = item.ProjectId }, null)