输入不是有效的Base-64字符串,因为它包含非基本64个字符,两个以上的填充字符或填充字符中的非法字符。在MVC4中 [英] he input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. in MVC4

查看:732
本文介绍了输入不是有效的Base-64字符串,因为它包含非基本64个字符,两个以上的填充字符或填充字符中的非法字符。在MVC4中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的查看代码---



型号IkkosAdminPortalWebSite.Models.RecordDetails



@ {

ViewBag.Title =添加;

布局=〜/ Views / Shared / _Layout.cshtml;

}



添加





@using(Html.BeginForm(添加, RecordDetails,FormMethod.Post,new {enctype =multipart / form-data,@ dat_ajax =false})){

@ Html.AntiForgeryToken()

@ Html.ValidationSummary(true)





RecordDetails



Below is my View Code---

model IkkosAdminPortalWebSite.Models.RecordDetails

@{
ViewBag.Title = "Add";
Layout = "~/Views/Shared/_Layout.cshtml";
}

Add



@using (Html.BeginForm("Add", "RecordDetails", FormMethod.Post, new { enctype = "multipart/form-data", @data_ajax = "false" })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)


RecordDetails



@ Html.LabelFor(model => model.Actor)


@Html.LabelFor(model => model.Actor)






@ Html.EditorFor(model => model.Actor)

@ Html.ValidationMessageFor(model => model。演员)


@Html.EditorFor(model => model.Actor)
@Html.ValidationMessageFor(model => model.Actor)









@ Html.LabelFor(model => model.Owner)


@Html.LabelFor(model => model.Owner)






@ Html.EditorFor(model => ; model.Owner)

@ Html.ValidationMessageFor(model => model.Owner)


@Html.EditorFor(model => model.Owner)
@Html.ValidationMessageFor(model => model.Owner)









@ Html.LabelFor(model => model.Category)


@Html.LabelFor(model => model.Category)






@ Html.EditorFor(model => model.Category)

@ Html.ValidationMessageFor(model => model.Category)


@Html.EditorFor(model => model.Category)
@Html.ValidationMessageFor(model => model.Category)









@ Html.LabelFor(model => model.SubCategory)


@Html.LabelFor(model => model.SubCategory)






@ Html.EditorFor(model => model.SubCategory)

@ Html.ValidationMessageFor(model => model.SubCategory)


@Html.EditorFor(model => model.SubCategory)
@Html.ValidationMessageFor(model => model.SubCategory)









@ Html.LabelFor(model => model.Movement)


@Html.LabelFor(model => model.Movement)






@ Html.EditorFor(model => ; model.Movement)

@ Html.ValidationMessageFor(model => model.Movement)


@Html.EditorFor(model => model.Movement)
@Html.ValidationMessageFor(model => model.Movement)









@ Html.LabelFor(model => model.Thumbnail)

@ *< label for = 缩略图 >缩略图< /标签> * @


@Html.LabelFor(model => model.Thumbnail)
@* <label for="Thumbnail">Thumbnail</label> *@






< input type =filename = 缩略图id =缩略图/>



@ Html.ValidationMessageFor(model => model.Thumbnail)


<input type="file" name="Thumbnail" id="Thumbnail" />

@Html.ValidationMessageFor(model => model.Thumbnail)









@ Html.LabelFor(model => model.IAPProductId)< br $>

@Html.LabelFor(model => model.IAPProductId)






@ Html.EditorFor(model => model.IAPProductId)

@ Html.ValidationMessageFor(model => model.IAPProductId)


@Html.EditorFor(model => model.IAPProductId)
@Html.ValidationMessageFor(model => model.IAPProductId)



< input type =submitvalue =创建/>


<input type="submit" value="Create" />

public class RecordDetails
{
    public string Actor { get; set; }
    public string Owner { get; set; }
    public string Category { get; set; }
    public string SubCategory { get; set; }
    public string Movement { get; set; }
    public HttpPostedFileBase Thumbnail { get; set; }
    public string IAPProductId { get; set; }
}





********

在Controller ActionResult代码中:



[HttpPost]

public ActionResult Add(RecordDetail record,HttpPostedFileBase Thumbnail)

// public ActionResult Add (RecordDetail记录)

{

if(ModelState.IsValid)

{



RecordDetail objrec = new RecordDetail();

if(Thumbnail!= null&& Thumbnail.ContentLength> 0)

{

var filename = Path.GetFileName(Thumbnail.FileName);

objrec.Thumbnail = System.Text.Encoding.UTF8.GetBytes(filename);



}



objList.RecordDetails.Add(record);



objList.SaveChanges ();

返回RedirectToAction(RecordDetails);

}

返回查看(记录);

}



*****************

数据库---缩略图列数据类型是图像。



********
In Controller ActionResult code:

[HttpPost]
public ActionResult Add(RecordDetail record, HttpPostedFileBase Thumbnail)
// public ActionResult Add(RecordDetail record)
{
if (ModelState.IsValid)
{

RecordDetail objrec = new RecordDetail();
if (Thumbnail != null && Thumbnail.ContentLength > 0)
{
var filename = Path.GetFileName(Thumbnail.FileName);
objrec.Thumbnail = System.Text.Encoding.UTF8.GetBytes(filename);

}

objList.RecordDetails.Add(record);

objList.SaveChanges();
return RedirectToAction("RecordDetails");
}
return View(record);
}

*****************
DataBase ---Thumbnail Column DataType is Image.

推荐答案

您没有解释您在标题中提出的问题与其余问题的关系。抛出异常的代码片段与将某些数据读取为base64有关(可以使用此方法完成: http://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx [<一个href =http://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspxtarget =_ blanktitle =New Window> ^ ],或类似的东西)。而你没有展示这段代码。但是,很可能,您的输入数据不是base64数据。找到这段代码并检查。



此外,在调试器下捕获异常并查看Debug WindowsCall stack。它会告诉你来电的来源。



-SA
You did not explain how your question formulated in the title related to the rest of the question. The piece of code throwing the exception is related to reading some data as base64 (which could be done using this method: http://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx[^], or something similar). And you did not show this piece of code. However, most likely, your input data is not base64 data. Locate this piece of code and check up.

Besides, catch the exception under debugger and look at the Debug Windows "Call stack". It will show you where the call came from.

—SA


这篇关于输入不是有效的Base-64字符串,因为它包含非基本64个字符,两个以上的填充字符或填充字符中的非法字符。在MVC4中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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