Link to home
Create AccountLog in
Avatar of Moti Mashiah
Moti MashiahFlag for Canada

asked on

Asp.net mvc5

Hi Guys,

I'm trying to break a string which comes from SQL to 4 columns and send it to view.
Here is how I'm getting the string from sql:
"ISLAND CONSTRUCTION \nISCON1 \nPO BOX 1210\n 35 BERNARD DR \n3239337"

Open in new window


I divided it by 4 columns as you can see above,

Now I'm trying to loop it 4 time and send it to show in view:

My controller:
var x = aldb.ERPJournala(refid, trantype, batcnum).FirstOrDefault();

for (int i = 0; i < x.BillTo.Length; i++)
            {
                if (i > 4)
                {
                    break;
                }
                else
                {
                    jr.Billto = x.BillTo.Split('\n')[i];
                }

            }

Open in new window


So far everything works fine I query the billTo and split it to 4 columns.

Now I don't know what to do at my view side:
Here below you can see what I'm doing:

<div class="col-md-3 col-sm-3 col-xs-3">
                     @for (int i = 0; i < Model.Billto.Length; i++)
                     {
                         @Model.Billto<br />
                     }
                 </div>  

Open in new window


The issue is that I'm getting just the last split like the last column.

I think my issue is the code in the view side.

Please,  help.


Thanks.
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

A few errors in your code, perhaps this code will help you
  using System;
using System.Linq;

namespace ee28966397
{
    class Program
    {
        static void Main(string[] args)
        {
          //string Billto = "ISLAND CONSTRUCTION \nISCON1 \nPO BOX 1210\n 35 BERNARD DR \n3239337";
            string Billto = "ISLAND CONSTRUCTION \nPO BOX 1210\n 35 BERNARD DR \n3239337";
            string[] Address;
            Address = Billto.Split('\n');
            Console.WriteLine("Number of items in Split {0}",Address.Length);
            Console.WriteLine("Name: {0}" , Address[0].Trim());
            Console.WriteLine("Address 1: {0}", Address[1].Trim());
            Console.WriteLine("Address 2: {0}", Address[2].Trim());
            Console.WriteLine("Address 3: {0}", Address[3].Trim());
            try
            {
                Console.WriteLine("Address 4: {0}", Address[4].Trim());
            }
            catch { };
            Console.ReadLine();

        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Moti Mashiah
Moti Mashiah
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Moti Mashiah

ASKER

Solved