各位大侠请帮忙,MVC/MVP模式接口编译错误,没辙了!
kmcyz 2018-08-28 08:55:04 很简单的一个MVP接口实现:
//View接口
namespace WebClient1.Products.Views
{
public interface IProductNewView
{
List<Product> Products { set; }
}
}
//View实现
namespace WebClient1.Products.Views
{
public partial class ProductNew : Microsoft.Practices.CompositeWeb.Web.UI.Page, IProductNewView
{
private ProductNewPresenter _presenter;
private List<Product> _p=null;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this._presenter.OnViewInitialized();
}
this._presenter.OnViewLoaded();
}
[CreateNew]
public ProductNewPresenter Presenter
{
get
{
return this._presenter;
}
set
{
if(value == null)
throw new ArgumentNullException("value");
this._presenter = value;
this._presenter.View = this;
}
}
// TODO: Forward events to the presenter and show state to the user.
// For examples of this, see the View-Presenter (with Application Controller) QuickStart:
public List<Product> Products
{
set
{
_p = value;
}
}
}
}
//Presenter
namespace WebClient1.Products.Views
{
public class ProductNewPresenter : Presenter<IProductNewView>
{
// NOTE: Uncomment the following code if you want ObjectBuilder to inject the module controller
// The code will not work in the Shell module, as a module controller is not created by default
//
private IProductsController _controller;
public ProductNewPresenter([CreateNew] IProductsController controller)
{
_controller = controller;
}
public override void OnViewLoaded()
{
// TODO: Implement code that will be executed every time the view loads
View.Products = _controller.Products;
}
}
}
编译错误:
错误 2 “WebClient1.Products.Views.ProductNew”不实现接口成员“WebClient1.Products.Views.IProductNewView.Products”。“WebClient1.Products.Views.ProductNew.Products”无法实现“WebClient1.Products.Views.IProductNewView.Products”,因为它没有匹配的返回类型“System.Collections.Generic.List<WebClient1.Products.Interface.Product>”。 c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\webclient1\6dba2d22\5c066a95\App_Web_1wkctjkb.2.cs 15