문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

new { Id = item.Id.Split(new char[] {'/'}).Last() }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top