Display text coming from the database under @Html.Actionlink()

Asked

Viewed 124 times

2

Well, I have the following scenario:

I make an appointment at database and I bring a IEnumerable<> to the View:

 <section class="container">
    <article class="row">
        @foreach (var item in Model)
        {
            <div class="col-md-4">
                <div class="thumbnail">
                    <h3 style="background-color:orangered; margin:0; text-align:center;color:white;">@Html.ActionLink(item.Titulo, "MostraPublicacao", "Publicacao", new { id = item.PublicacaoId })</h3>     
                    <img src="~/Uploads/Imagens/teste.jpg" class="col-md-12 " style="padding:0;" />
                    <div>
                        @Html.DisplayFor(model => item.Resumo);
                    </div>
                </div>
            </div>
        }
    </article>
</section>

So my TITTULLE is received by this line

@Html.DisplayFor(model => item.Resumo);

I need to display the text of the summary in a @Html.ActionLink() to be a link in order to redirect to another View, that will receive the ID of this object as parameter

An image to try to illustrate the problem better:

inserir a descrição da imagem aqui

How do I solve this problem ?

1 answer

2


In place of @Html.DisplayFor(model => item.Resumo) just switch to something like:

@Html.ActionLin(item.resumo, "ACTION", "CONTROLLER", new{id = item.PUBLICACAOID})

This way, the text will be the summary, but the generated HTML will be something like:

<a href="/CONTROLLER/ACTION/ID"> @item.titulo </a>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.