Solved

Asp.net mvc5

Posted on 2016-08-29
3
27 Views
Last Modified: 2016-09-03
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.
0
Comment
Question by:Moti Mashiah
  • 2
3 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 41775662
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

0
 
LVL 1

Accepted Solution

by:
Moti Mashiah earned 0 total points
ID: 41775679
Thank you for your answer, but it wasn't related to what I was asking for.

Please, look at my solution:

Controller
 var x = aldb.ERPJournala(refid, trantype, batcnum).FirstOrDefault();
jr.Billto = x.BillTo;

Open in new window


View:
<div class="col-md-6 col-sm-6 col-xs-6">
                <div class="col-md-3 col-sm-3 col-xs-3">
                    <b>Bill To:</b>
                </div>
                 
                     @for (int i = 0; i < Model.Billto.Length; i++)
                     {
                         if (i > 4)
                         {
                             break;
                         }
                         else
                         {
                             Model.Billtoview  = Model.Billto.Split('\n')[i];
                         }
                         @Model.Billtoview<br />
                     }
                  
            </div>

Open in new window

0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 41782790
Solved
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now