Solved

Asp.net mvc5

Posted on 2016-08-29
3
20 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
Comment Utility
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
Comment Utility
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
Comment Utility
Solved
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

14 Experts available now in Live!

Get 1:1 Help Now