Domanda

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?

È stato utile?

Soluzione

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) }

Altri suggerimenti

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

new { Id = item.Id.Split(new char[] {'/'}).Last() }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top