ViewDataFactory和强类型的母版页 [英] ViewDataFactory and strongly typed master pages

查看:99
本文介绍了ViewDataFactory和强类型的母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着让我的强类型的母版页在我的ASP MVC 2.0应用程序的工作。

Im trying to get my strongly typed master page to work in my ASP MVC 2.0 application. I have come far with the help of these two posts:

<一个href=\"http://stackoverflow.com/questions/78548/passing-data-to-master-page-in-asp-net-mvc/746011#746011\">Passing数据母版页的ASP.NET MVC

<一个href=\"http://www.matthewlowrance.com/matthewlowrance/post/2009/11/11/Strongly-Typed-ASPNet-MVC-Master-Pages.aspx\"相对=nofollow>强类型的ASP.Net MVC母版页

问题是,林不知道如何获取ViewDataFactory code的工作,这是我的code:

Problem is that im not sure how to get that ViewDataFactory code to work, this is my code:

BaseController.cs

public class BaseController : Controller
{        
    private IPageRepository _repPage;

    public BaseController(IPageRepository repPage)
    {
        _repPage = repPage;
    }

    protected T CreateViewData<T>() where T : MasterViewData, new()
    {
        IViewDataFactory factory = new ViewDataFactory();

        IEnumerable<Page> pages = _repPage.GetAllPages();

        return factory.Create<T>(pages);
    }
}

HomeController.cs

public class HomeController : BaseController
{
    public ActionResult Index()
    {
        HomeViewData viewData = CreateViewData<HomeViewData>();

        viewData.Name = "Test";

        return View("Index", viewData);
    }

    public ActionResult About()
    {
        return View();
    }
}

ViewDataFactory.cs

public interface IViewDataFactory
{
    T Create<T>(IEnumerable<Page> pages) where T : MasterViewData, new()
}

public class ViewDataFactory : IViewDataFactory
{
    public ViewDataFactory()
    {
    }  
}

HomeViewData.cs

public class HomeViewData : MasterViewData
{
    public string Name { get; set; }
}

MasterViewData

public class MasterViewData
{
    public IEnumerable<Page> Pages { get; set; }
}

当我建立的解决方案,我得到follwing生成错误:

When I build the solution I get the follwing build error:

"; expected" in ViewDataFactory.cs

,它指向code片断:

Which points to the code snippet:

T Create<T>(IEnumerable<Page> pages) where T : MasterViewData, new()

我猜IM失去了一些东西必不可少,即时通讯新的这个和任何帮助将AP preciated!

I guess im missing something essential, im new to this and any help would be appreciated!

推荐答案

为什么你不只是在该行​​的末尾添加一个分号? :)

Why don't you just add a semicolon at the end of that line? :)

抽象方法(以及接口方法)有一个分号代替身体。

Abstract methods (as well as interface methods) have a semicolon in place of a body.

这篇关于ViewDataFactory和强类型的母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆