Solved

Method is returning a query

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
make control visible based off other control value 7 44
Inserting LocalDB Table to SQL Server C# 3 47
asp.net mvc5 6 33
Adding Rows to Grid 4 31
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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

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