[RESOLVED]How to split a String in views

i have different responsibilites for displaying but i am saving all the responsibilites in a single column in database using with special symbol lile "&&" for each and every responsibilites

and i am trying to split this in view i am geting problem and it donesn’t work how can i split in a view

 <ul style="padding-left:30px;">
                                                           @foreach(var Resp in recent.Responsibilities.Split("&&"))  // here i am getting error it's not working has showing some invalid arguments
@foreach(var Resp in recent.Responsibilities.Split(new string[]{"&&"}))

Or you can use Regex.Split:

@foreach(var Resp in Regex.Split(recent.Responsibilities, "&&"))

You will probably have to add

using System.Text.RegularExpressions

to the top of your View if you use the Regex option.

Fix your table. Don’t concatenate values like that in one column. You should have a Responsibility table and another take for ResponsibilitySelection with keys defined appropriately. 


@foreach(var Resp in recent.Responsibilities.Split("&&"))

Look in documentation: http://msdn.microsoft.com/en-us/library/system.string.split(v=vs.110).aspx

There is no Split method that used 1 string argument.

You can try to use this http://msdn.microsoft.com/en-us/library/tabh47cf(v=vs.110).aspx 

... recent.Responsibilities.Split((new string[] {"&&"})[0]) ...

Hope this helps.

Leave a Reply