Home > Software engineering >  Create url in ASP. NET MVC
Create url in ASP. NET MVC

Time:05-27

I am developing an application in asp.net mvc and I want to create a url (You will see below).

I have already seen that there is this question @Html.ActionLink with the item Name as a link that does not answer my needs

@foreach (var item in Model) {
    <tr>
                
        <td>
            @Html.DisplayFor(modelItem => item.Data)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>   
        <td>
            @Html.DisplayFor(modelItem => item.NextTurnPlayer)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.State)
        </td>
        <td>
            @if(item.State.Equals("Conclusa")){
                @Html.DisplayFor(modelItem => item.Winner)
            }
        </td>
        <!--se non c'è neancora il secondo giocatore e il giocatore non è quello che ha creato la partita mostro partecipa-->
        @if(item.UsernamePlayer2 == null && item.UsernamePlayer1 != HttpContext.Current.User.Identity.Name){
            <td>
                @Html.ActionLink("Partecipate", "Partecipate", "Manage", new { Id= (string) @item.Name}, null)
            </td>
        }<!--se non ci sono entrambi giocatori e il giocatore loggato fa parte del match mostro gioca-->
        @if(item.UsernamePlayer2 != null && (item.UsernamePlayer1 == HttpContext.Current.User.Identity.Name || item.UsernamePlayer2 == HttpContext.Current.User.Identity.Name)){
            <td>
                @Html.ActionLink("Play!", "Game", "Manage", new { Id= (string) @item.Name}, null)
            </td>
        }
    </tr>
}

It gives me the following url:

https://localhost:44398/Manage/Partecipate/Ciao

But i want to have

https://localhost:44398/Manage/Partecipate?Name=Ciao

CodePudding user response:

Did you try to change the route parameter name to Name?

@Html.ActionLink("Partecipate", "Partecipate", "Manage", new { Name = item.Name}, null)
  • Related