?
Solved

Asp.net mvc5

Posted on 2016-08-29
3
Medium Priority
?
55 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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