我是 MVP 模式的新手。我不太清楚在哪里编写将文件上传到服务器的逻辑,然后在上传后执行一些验证步骤和数据库操作。请指教。
public interface IPresenter
{
void UploadFile(string fileName); //For simplicity, file name is passed;
//it can be declared as a property
}
public interface IDefaultView
{
void Upload();
}
public class DefaultPresenter : IPresenter
{
protected DefaultPresenter() {}
public DefaultPresenter(IDefaultView defaultview)
{
this.defaultView = defaultView;
}
public void UploadFile(string fileName)
{
//Do I need to write saving functionality here or call
//defaultView.Upload(fileName)?
//
//From online articles, I have seen all business functionality written here.
//But I think I will not be able to use System.Web in this layer.
}
}
public partial class UploadExtract: IDefaultView
{
public void Upload(fileName)
{
}
}
最佳答案
您将无法在业务逻辑中使用 System.Web
。而且,事实上,您不应该这样做。
您可以编写您的 Controller 以接受来自客户端的文件并将其保存在本地服务器中的某个位置。然后,将文件名传递给您的业务逻辑层以进行进一步处理。
你的后续问题:
Q. I am reading the file into a memory stream. Is it advisable to pass the memory stream to the presenter, perform the business logic in the presenter, and finally set the file upload status in view?
是的,这也有效:传递流而不是文件名。
关于c# - 实现文件上传的 MVP 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14368651/