开发者

how to display table data or pass view data on site.master page in asp mvc2

i want to show my table data on site.master page and display that data all action method plz any one help me or give me sample code my model and controller code is here

    namespace DomainModel.Entities
  {

    [Table(Name = "Requirements")]
public class Requirement

  {
public int  RequirementID{ get; set; }
 [Column] public int Experience { get; set; }
 [Column] public string JobTitle { get; se开发者_JAVA技巧t; }
 [Column] public string Qualification { get; set; }
 [Column] public string Location { get; set; }
 [Column] public int Budget { get; set; }
 [Column] public DateTime Date { get; set; } 
      }

       }

my Repository code is here

namespace DomainModel.Concrete
 {
public class SqlCandidateRepository : ICandidateRepository
{

 private Table<Requirement> Requirementtable;

  public SqlCandidateRepository(string connectionString)
    {

  Requirementtable = (new DataContext(connectionString)).GetTable<Requirement>();

   public IQueryable<Requirement> NewRequirement()
    { 
    return  from d in Requirementtable where d.Date>=System.DateTime.Now select d;

    }

here is my controller code

  public ActionResult ShownewRequirement()
    {

     ViewData[" requirement"] = IcandidateRepository.NewRequirement();
      return View();

    }


+1 Good question.

Since master pages do not take any models. To be able to access data from within your master pages use ViewData (or ViewBag if ASP.NET MVC3) within a base controller.

In all controllers that will use that master page in the views they populate, I make those controllers children of a base controller, let's call it BaseController.

Example:

public abstract class BaseController : Controller
{
    public BaseController()
    {
        ViewData["MyName"] = "LordCover";
    }
}

Now, in your master page's markup, you can use this:

<h2>Hello <%: ViewData["MyName"] %>!</h2>

The output will be:

Hello LordCover!

I repeat, to make all of your controllers get advantage of this controller they must inherit from it.

Hope that helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜