0

I have model with LINQ that will return Rows. here my code in model class on this query i want to return the result in View. how can i do that?

    public void retNumRecord(string email, string fname, 
                             string lname, string zip, string pref, 
                             string address, string tel)
    {
        int _pref = Convert.ToInt32(pref); 

        var x = (from p in db.eduardo_member_t
                 where (p.email != null && p.email.Contains(email))
                    || (p.fname != null && p.fname.Contains(fname))
                    || (p.lname != null && p.lname.Contains(lname))
                    || (p.zip != null && p.zip.Contains(zip))
                    || (p.pref != null && p.pref == _pref)
                    || (p.address != null && p.address.Contains(address))
                    || (p.tel != null && p.tel.Contains(tel))
                 select p); 

        return x;
    }
2
  • 1
    is void but you are returning x. (?) Commented Apr 9, 2012 at 2:54
  • sorry for the confusion .. my program have a search form and by that query i want to return the result in View. how can i do that. im confuse doint this in MVC 3? Commented Apr 9, 2012 at 2:58

3 Answers 3

1

You need to put that as a model in your view and the call

return View( retNumRecord(...) );

in your action

Sign up to request clarification or add additional context in comments.

1 Comment

You should read some tutorials about mvc3, it's the fist thing they told. you need to put whatever type that query return as the view mdoel (weblogs.asp.net/gunnarpeipman/archive/2010/10/13/…) and then pass the query result as a parameter of the View method in your controller.
0

A void will not return anything. You need an ActionResult.

public ActionResult retNumRecord(....
{
   .....

   return View(x);
}

This assumes you have a view called 'retNumRecord', if not then:

return View("yourviewname", x);

Or, if this is an ajax call:

return Json(x);

Comments

0

You would call the method in your controller and then return View(retNumRecord(..));

Right click on your controller name and then create a view. Once you are in the view, You can make a for loop to print out each row.

Follow the music store tutorial as it can get you up to speed with MVC3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.