7

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

0

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Unfortunately, you cannot use MVC helpers in App_Code. You can still use WebPages helpers.
OK, but how to create my helper??
@Leandro: You can do something like this: stackoverflow.com/questions/4710853/…
@SLaks Thank you this saved my bacon. My deploy script excluded *.config when copying the website to the server....
I was using a page outside the Views folder and got this error, which disappeared after adding the @using directive. I'll try and figure if I can also change web.config to fix it; just as an exercise. Bookmarked slaks blog. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.