Frage

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?

War es hilfreich?

Lösung

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

Andere Tipps

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

new { Id = item.Id.Split(new char[] {'/'}).Last() }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top