Solved

Method is returning a query

Posted on 2015-01-06
4
111 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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