.net MVC表单以上载文件和其他字段
我有一个.NETMVCEF应用程序。我需要创建一个表单,将文件和其他字段上传到数据库中(如文件本身和文件描述、类别等)。我在SQL Server数据库中有一个表,其中包含FileStream(因此是varbinary(max)) 表:.net MVC表单以上载文件和其他字段,.net,sql-server,forms,entity-framework,model-view-controller,.net,Sql Server,Forms,Entity Framework,Model View Controller,我有一个.NETMVCEF应用程序。我需要创建一个表单,将文件和其他字段上传到数据库中(如文件本身和文件描述、类别等)。我在SQL Server数据库中有一个表,其中包含FileStream(因此是varbinary(max)) 表: 创建表[dbo].[MyDocuments]( [ID][uniqueidentifier]不为空, [docID][uniqueidentifier]ROWGUIDCOL不为空, [document][varbinary](max)FILESTREAM不为空,
创建表[dbo].[MyDocuments](
[ID][uniqueidentifier]不为空,
[docID][uniqueidentifier]ROWGUIDCOL不为空,
[document][varbinary](max)FILESTREAM不为空,
[docName][nvarchar](40)不为空,
[docLink][nvarchar](最大值)空,
[docCategory][text]空,
[docPermission][nvarchar](15)无效,
[docTeam][nvarchar](15)空,
[docassigndate][date]空,
[docCompletedDate][date]空,
[docArchivedDate][date]NULL)
型号:
public partial class MyDocument
{
public System.Guid ID { get; set; }
public System.Guid docID { get; set; }
public byte[] document { get; set; }
public string docName { get; set; }
public string docLink { get; set; }
public string docCategory { get; set; }
public string docPermission { get; set; }
public string docTeam { get; set; }
public Nullable<System.DateTime> docAssigmentDate { get; set; }
public Nullable<System.DateTime> docCompletedDate { get; set; }
public Nullable<System.DateTime> docArchivedDate { get; set; }
}
公共部分类MyDocument
{
public System.Guid ID{get;set;}
public System.Guid docID{get;set;}
公共字节[]文档{get;set;}
公共字符串docName{get;set;}
公共字符串docLink{get;set;}
公共字符串docCategory{get;set;}
公共字符串docPermission{get;set;}
公共字符串docTeam{get;set;}
公共可为空的docassigndate{get;set;}
公共可为空的docCompletedDate{get;set;}
公共可为空的docArchivedDate{get;set;}
}
我需要有一个表单,允许用户输入信息,包括一个文件的浏览上传和提交到数据库表的一切。所以我需要控制器和视图的帮助。是否有一个很好的示例代码或说明,我可以如何做到这一点。举个例子肯定会有帮助。多谢各位
ifformfile yourformfiledname
来接收数据(获取字节数组)对不起,我的答案是针对Asp.net核心的
对于asp.net,我认为您可以使用
HttpContext.Current.Request.File
来接收您请求的框架文件asp.net MVC
或asp.net核心MVC
,您的问题不清楚。上传文件与entityframework无关,EF是关于查询/将数据保存到数据库,上传文件是关于从浏览器接收数据。它是asp.net-MVC