Solved

Method is returning a query

Posted on 2015-01-06
4
107 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
  • 3
4 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
index Out OF Range Exception error 4 32
C# Error - Add Failed 12 52
Showdialog 8 21
Events in static methods 3 27
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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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