C# 将数据从视图传递到操作方法时出现运行时错误
试图将数据从视图传递到操作后方法时,浏览器中出现运行时错误。 错误: 输入不是有效的Base-64字符串,因为它包含非Base-64字符、两个以上的填充字符或填充字符中的非法字符 这是我的行动方法:C# 将数据从视图传递到操作方法时出现运行时错误,c#,asp.net-mvc-5,entity-framework-6,C#,Asp.net Mvc 5,Entity Framework 6,试图将数据从视图传递到操作后方法时,浏览器中出现运行时错误。 错误: 输入不是有效的Base-64字符串,因为它包含非Base-64字符、两个以上的填充字符或填充字符中的非法字符 这是我的行动方法: MyContext db = new MyContext(); public ActionResult SaveGen(Enroll_Gen Enrollment,HttpPostedFileBase file) { int i = UploadDataInDataBase(file,
MyContext db = new MyContext();
public ActionResult SaveGen(Enroll_Gen Enrollment,HttpPostedFileBase file)
{
int i = UploadDataInDataBase(file,Enrollment);
if (i == 1)
{
return RedirectToAction("Index");
}
return RedirectToAction("Guardian");
}
public int UploadDataInDataBase(HttpPostedFileBase file, Enroll_Gen EnrollGEn)
{
EnrollGEn.Photo = ConvertToBytes(file);
var Enroll_Gen = new Enroll_Gen
{
AdmnNum = EnrollGEn.AdmnNum,
Class = EnrollGEn.Class,
Section = EnrollGEn.Section,
AcademicYear_Batch = EnrollGEn.AcademicYear_Batch,
DateOfAdmission=EnrollGEn.DateOfAdmission,
RollNum =EnrollGEn.RollNum,
Regt_Numb = EnrollGEn.Regt_Numb,
Photo = EnrollGEn.Photo,
FirstName=EnrollGEn.FirstName,
MiddleName=EnrollGEn.MiddleName,
LastName=EnrollGEn.LastName,
DOB=EnrollGEn.DOB,
Mobile=EnrollGEn.Mobile,
Gender=EnrollGEn.Gender,
Nationality=EnrollGEn.Nationality,
Language=EnrollGEn.Language,
Religion=EnrollGEn.Religion,
BloodGroup=EnrollGEn.BloodGroup,
Address=EnrollGEn.Address,
Country=EnrollGEn.Country,
State=EnrollGEn.State,
City=EnrollGEn.City,
PinCode=EnrollGEn.PinCode,
WebUrl=EnrollGEn.WebUrl
};
db.Enroll_Gens.Add(Enroll_Gen);
int i = db.SaveChanges();
if (i == 1)
{
return 1;
}
else
{
return 0;
}
}
public byte[] ConvertToBytes(HttpPostedFileBase image)
{
byte[] imageBytes = null;
BinaryReader reader = new BinaryReader(image.InputStream);
imageBytes = reader.ReadBytes((int)image.ContentLength);
return imageBytes;
}
这是模型类:
public partial class Enroll_Gen
{
public Enroll_Gen()
{
this.Entrance = new HashSet<Entrance>();
this.QualNAchi = new HashSet<QualNAchi>();
this.Scholarship = new HashSet<Scholarship>();
}
[Key]
public string AdmnNum { get; set; }
public string Class { get; set; }
public string Section { get; set; }
public int AcademicYear_Batch { get; set; }
public string DateOfAdmission { get; set; }
public int RollNum { get; set; }
public string Regt_Numb { get; set; }
public byte[] Photo { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string DOB { get; set; }
public string Mobile { get; set; }
public string Gender { get; set; }
public string Nationality { get; set; }
public string Language { get; set; }
public string Religion { get; set; }
public string BloodGroup { get; set; }
public string Address { get; set; }
public string Country { get; set; }
public string State { get; set; }
public string City { get; set; }
public string PinCode { get; set; }
public string WebUrl { get; set; }
public virtual ICollection<Entrance> Entrance { get; set; }
public virtual ICollection<QualNAchi> QualNAchi { get; set; }
public virtual ICollection<Scholarship> Scholarship { get; set; }
}
公共部分类注册\u Gen
{
公开注册
{
this.entry=new HashSet();
this.QualNAchi=new HashSet();
this.Scholarship=newhashset();
}
[关键]
公共字符串AdmnNum{get;set;}
公共字符串类{get;set;}
公共字符串部分{get;set;}
公共int\u批处理{get;set;}
公共字符串DateOfAdministration{get;set;}
public int RollNum{get;set;}
公共字符串Regt_Numb{get;set;}
公共字节[]Photo{get;set;}
公共字符串名{get;set;}
公共字符串MiddleName{get;set;}
公共字符串LastName{get;set;}
公共字符串DOB{get;set;}
公共字符串Mobile{get;set;}
公共字符串{get;set;}
公共字符串{get;set;}
公共字符串语言{get;set;}
公共字符串{get;set;}
公共字符串BloodGroup{get;set;}
公共字符串地址{get;set;}
公共字符串国家{get;set;}
公共字符串状态{get;set;}
公共字符串City{get;set;}
公共字符串PinCode{get;set;}
公共字符串WebUrl{get;set;}
公共虚拟ICollection入口{get;set;}
公共虚拟ICollection QualNAchi{get;set;}
公共虚拟ICollection奖学金{get;set;}
}
您的操作参数看起来无效,您的操作参数中的Enroll\u Gen Enrollment
是一个模型类,我正在从Enrollment中的view接收值