渲染部分或渲染动作

发布于 2024-08-30 18:57:29 字数 3705 浏览 3 评论 0原文

采取产生活跃职位空缺的行动。代码如下;

公共 ViewResult OpenVacancies() { var openvacancies = db.GetActiveVacancies(); 返回视图(空缺职位); 我

想在几个页面上使用这个列表,所以我想最好使用的是 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>

have an action that generates active vacancies. The code is below;

public ViewResult OpenVacancies()
{
var openvacancies = db.GetActiveVacancies();
return View(openvacancies);
}

I want to use this list on several pages so i guess the best thing to use is html.renderaction (please correct me if i am wrong here).

Please note that the view and .ascx control are in an Area.

I then created a view by right clicking inside the action and create a .ascx and a strongly typed view of Vacancy. I chose a view content of "List".

I then added this line to the required page;

Please note that the view and .ascx control are in an Area.

The error i got is;

The type or namespace name 'Vacancy' could not be found (are you missing a using directive or an assembly reference?)

the .ascx code is below;

>" %>

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度° 2024-09-06 18:57:29

首先,如果您只是想在多个页面上重用视图,则应该使用共享部分视图(将其放在共享文件夹中)和 <% Html.RenderPartial("OpenVacancies"); %>。

其次,根据您的代码片段,您的部分视图似乎不是强类型的。而不是

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

你会想要这样的东西:

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

First, if you simply want to reuse your view on multiple pages, you should be using a shared partial view (place it in the Shared folder) with <% Html.RenderPartial("OpenVacancies"); %>.

Second, based on your code snippet, your partial view doesn't appear to be strongly typed. Instead of

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

you will want something like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Vacancy>>" %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文