Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Method is returning a query

Posted on 2015-01-06
4
Medium Priority
?
120 Views
Last Modified: 2016-02-17
I have no idea what I'm doing wrong here but I have an action
public ActionResult Edit(string id)

        {                

            CWRepository CWA = new CWRepository();         

            var vm = new MerchantAgentViewModel()
            {
                merchantinfo = CWA.GetMerchantInfo(id),
                merchantpercentages = CWA.GetMerchantPercentages(id),
                getAgent1 = CWA.getAgentName(CWA.GetMerchantInfo(id).AGENT_ID.Value),
                getAgent2 = CWA.getAgentName(CWA.GetMerchantInfo(id).AGENT_ID2.Value),
                getAgent3 = CWA.getAgentName(CWA.GetMerchantInfo(id).AGENT_ID3.Value),
                getAgent4 = CWA.getAgentName(CWA.GetMerchantInfo(id).AGENT_ID4.Value)
            };        

              return View(vm);
        }

Open in new window

I have this in my repository
public string getAgentName(int id)
        {
            using (CWA_MerchantEntities context = getDataContext())
            {
                var info = (from n in context.MERCHANT_AGENT
                            where n.Agent_ID == (id)
                            select n.Agent_F_Name + " " + n.Agent_L_Name   
                      );
                return info.ToString();              

            }
        }

Open in new window


and this in my view
@Html.TextBoxFor(model => model.getAgent1, new { @class = "AgentName" })

Open in new window

The textboxes which should show the agents name, is filled with a query VS must be running.

What am I doing wrong.

Thanks in advance
0
Comment
Question by:Niall292
[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
  • 3
4 Comments
 
LVL 27

Accepted Solution

by:
Shaun Kline earned 2000 total points
ID: 40534292
The variant that is returned from your LINQ query is most likely a list of objects. Try using info.First().ToString().
0
 

Author Comment

by:Niall292
ID: 40534313
I did try that before and got the same return but just to be sure I will try it again
0
 

Author Comment

by:Niall292
ID: 40534320
I apologise I went back and read your reply properly because I had posted what I had tried.
When I read it again I noticed the .first. and that was the right answer. Thank you

I was struggling with that for hours
0
 

Author Closing Comment

by:Niall292
ID: 40534322
Something so simple. Thank you
but then again everything is simple when you know the answer :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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