Solved

Asp.net mvc5

Posted on 2016-08-29
3
43 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 81

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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