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