Link to home
Start Free TrialLog in
Avatar of Niall Gallagher
Niall GallagherFlag for Ireland

asked on

Method is returning a query

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
ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Niall Gallagher

ASKER

I did try that before and got the same return but just to be sure I will try it again
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
Something so simple. Thank you
but then again everything is simple when you know the answer :)