Renderpartial or renderaction

Posted by femi on Stack Overflow See other posts from Stack Overflow or by femi
Published on 2010-04-30T21:34:03Z Indexed on 2010/04/30 21:37 UTC
Read the original article Hit count: 480

Filed under:
|
|
|

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;

<% Html.RenderAction("OpenVacancies"); %>

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;

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

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

© Stack Overflow or respective owner

Related posts about renderaction

Related posts about renderpartial