Pergunta

From my view, I try to pass a value looking like this Page/33,

The form looks like this:

<td>@Html.ActionLink("Edit", "CreatePage", new { Id = item.Id})</td>

So in this case item.Id = Page/33 and I would like to split the string by the "/"-char. Only sending in whatever comes after the /, 33 in this case

Can I do this in a simple way inside the form?

Foi útil?

Solução

You can use the IndexOf method to find the character, and the Substring method to get the part of the string after it:

new { Id = item.Id.Substring(item.Id.IndexOf('/') + 1) }

Outras dicas

While the solution posted by Guffa works, here some more simple:

new { Id = item.Id.Split(new char[] {'/'}).Last() }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top