开发者

mvc and entity framework, display results of linq query

I want to return the results of a query that is written in linq to my view page for a MVC application.

I want to c开发者_运维问答all my view, then pass the model, the model would have the results of my query.

How can I do this?


public ActionResult YourAction() {
  var results = GetResultsFromLinqQuery();
  return View(results);
}

public List<SomeObject> GetResultsFromLinqQuery() {
   var queryResults = // get these from your linq query
   return queryResults;
}

If you strongly type your view to expect results, then you can access them using Model.

Edit:

If your results is a List then in the view replace

Inherits="System.Web.Mvc.ViewPage"

with

Inherits="System.Web.Mvc.ViewPage<IEnumerable<SomeObject>>"

Edit 2:

If all of this is not making much sense to you, I suggest you to take a look at Nerd Dinner tutorial for ASP.NET MVC.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜