Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create custom Helper in ASP NET MVC 3 and Razor

I am creating a helper with ASP NET MVC 3 and Razor to display my grid

@helper ListaPessoa(IEnumerable<TesteHelpersMV3.Models.PessoaModel> listaPessoa) 
{    
    <table>
    <tr>
        <th></th>
        <th>Nome</th>
        <th>Endereco</th>
        <th>DataNascimento</th>
    </tr>

    @foreach (var item in listaPessoa)
    {
        <tr>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.Nome }) |
                @Html.ActionLink("Details", "Details", new { id = item.Nome }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.Nome })
            </td>
            <td>@item.Nome</td>
            <td>@item.Endereco</td>
            <td>@item.Cidade</td>
        </tr>
    }

    </table>
}

but the Razor can not find @Html.ActionLink and the following error occurs

Compiler Error Message: CS1061: 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink' and no extension method 'ActionLink' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

what is wrong? ?? how to solve this problem??

Thank You

Leandro Prado

like image 477
Leandro Prado Avatar asked Feb 11 '11 13:02

Leandro Prado


1 Answers

Add @using System.Web.Mvc.Html.

This is added automatically in Views\Web.config, so it won't apply to any pages outside of the Views folder.

like image 98
SLaks Avatar answered Oct 20 '22 07:10

SLaks