© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
25 replies
Gipper

How to pass variable from one View to another View in link?

Ok, so I have this code in my view:
@foreach (var item in Model)
{
    @if(Model.Any(utilizadorGrupo=>utilizadorGrupo.UtilizadorId == userID))
    {
        @if (userID == item.UtilizadorId)
        {

            <a id="nomeGrupo" href="@Url.Action("verPublicacaoGrupo")?nomeGrupo=@item.Grupo.Nome_grupo"><strong>@item.Grupo.Nome_grupo</strong></a>
        }
    }
}
@foreach (var item in Model)
{
    @if(Model.Any(utilizadorGrupo=>utilizadorGrupo.UtilizadorId == userID))
    {
        @if (userID == item.UtilizadorId)
        {

            <a id="nomeGrupo" href="@Url.Action("verPublicacaoGrupo")?nomeGrupo=@item.Grupo.Nome_grupo"><strong>@item.Grupo.Nome_grupo</strong></a>
        }
    }
}

as you can see, in this view I am including a link to another view, I loop through a collection of objects and would like to pass the value of one of the fields of that object (Nome_grupo) to the view being linked to. I am doing it in the Razor syntax way because it seemed simpler, but I am open to any other way as this one has proved a bit wonky.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How do i pass data from one form to another?
C#CC# / help
4y ago
❔ How to access variable from another class?
C#CC# / help
3y ago
❔ Linking folder from one project to another
C#CC# / help
3y ago