1

アクティブな欠員を生成するアクションがあります。コードは以下のとおりです。

public ViewResult OpenVacancy() { var openvacancies = db.GetActiveVacancy(); ビューを返します(空き状況); }

このリストを複数のページで使用したいので、html.renderaction を使用するのが最適だと思います (ここで間違っている場合は訂正してください)。

ビューと .ascx コントロールはエリア内にあることに注意してください。

次に、アクション内で右クリックしてビューを作成し、.ascx と Vacancy の厳密に型指定されたビューを作成します。「一覧」の表示内容を選択しました。

次に、この行を必要なページに追加しました。

ビューと .ascx コントロールはエリア内にあることに注意してください。

私が得たエラーは次のとおりです。

型または名前空間名 'Vacancy' が見つかりませんでした (using ディレクティブまたはアセンブリ参照がありませんか?)

.ascx コードは以下のとおりです。

>" %>
<table>
    <tr>
        <th></th>
        <th>
            VacancyID
        </th>
        <th>
            JobTitle
        </th>
        <th>
            PositionID
        </th>
        <th>
            LocationID
        </th>
        <th>
            JobDescription
        </th>
        <th>
            JobConditions
        </th>
        <th>
            Qualifications
        </th>
        <th>
            RequiredSkills
        </th>
        <th>
            Certifications
        </th>
        <th>
            AdvertDate
        </th>
        <th>
            AdvertExpiryDate
        </th>
        <th>
            Status
        </th>
        <th>
            StaffLevel
        </th>
        <th>
            LineManagerEmail
        </th>
        <th>
            ApprovalFlag
        </th>
        <th>
            RequisitionDate
        </th>
    </tr>

<% foreach (var item in Model) { %>

    <tr>
        <td>
            <%= Html.ActionLink("Edit", "Edit", new { id=item.VacancyID }) %> |
            <%= Html.ActionLink("Details", "Details", new { id=item.VacancyID })%> |
            <%= Html.ActionLink("Delete", "Delete", new { id=item.VacancyID })%>
        </td>
        <td>
            <%= Html.Encode(item.VacancyID) %>
        </td>
        <td>
            <%= Html.Encode(item.JobTitle) %>
        </td>
        <td>
            <%= Html.Encode(item.PositionID) %>
        </td>
        <td>
            <%= Html.Encode(item.LocationID) %>
        </td>
        <td>
            <%= Html.Encode(item.JobDescription) %>
        </td>
        <td>
            <%= Html.Encode(item.JobConditions) %>
        </td>
        <td>
            <%= Html.Encode(item.Qualifications) %>
        </td>
        <td>
            <%= Html.Encode(item.RequiredSkills) %>
        </td>
        <td>
            <%= Html.Encode(item.Certifications) %>
        </td>
        <td>
            <%= Html.Encode(String.Format("{0:g}", item.AdvertDate)) %>
        </td>
        <td>
            <%= Html.Encode(String.Format("{0:g}", item.AdvertExpiryDate)) %>
        </td>
        <td>
            <%= Html.Encode(item.Status) %>
        </td>
        <td>
            <%= Html.Encode(item.StaffLevel) %>
        </td>
        <td>
            <%= Html.Encode(item.LineManagerEmail) %>
        </td>
        <td>
            <%= Html.Encode(item.ApprovalFlag) %>
        </td>
        <td>
            <%= Html.Encode(String.Format("{0:g}", item.RequisitionDate)) %>
        </td>
    </tr>

<% } %>

</table>

<p>
    <%= Html.ActionLink("Create New", "Create") %>
</p>
4

1 に答える 1

0

まず、ビューを複数のページで単に再利用したい場合は、<% Html.RenderPartial("OpenVacancies"); で共有部分ビューを使用する (Shared フォルダーに配置する) 必要があります。%>.

第 2 に、コード スニペットに基づいて、部分ビューは厳密に型指定されているようには見えません。それ以外の

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

次のようなものが必要になります。

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Vacancy>>" %>
于 2010-05-05T07:52:33.527 に答える