输入不是有效的Base-64串,因为它含有非基本64字符? [英] The input is not a valid Base-64 string as it contains a non-base 64 character?

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

问题描述

我有一个表格,其中的网站下载部分用户可以上传一个文件。然而,当表单提交我得到这个错误,没有要求过做它的操作方法。

I have a form where a user can upload a file to the sites download section. However when the form is submitted I get this error, without the request ever making it to the action method.

的输入是不是有效的Base-64串,因为它含有非基本64字符,两个以上的填充字符,或填充字符之间的非空白字符

"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."

code:

[HttpPost]
    [Authorize]
    public ActionResult Create(Download dl, HttpPostedFileBase DownloadFile)
    {

@model Models.Download

@{
    ViewBag.Title = "Add Download";
}

<h3>Add Download</h3>

@using (Html.BeginForm("Create", "Download", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)

    <div class="editor-label">Download File</div>
    <div class="editor-field">
        <input name="DownloadFile" id="DownloadFile" type="file" />
        @Html.ValidationMessage("DownloadFile");
    </div>

    <div class="editor-label">@Html.LabelFor(model => model.Downloads)</div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Downloads)
        @Html.ValidationMessageFor(model => model.Downloads)
    </div>

    <div class="editor-label">@Html.LabelFor(model => model.DownloadDate)</div>
    <div class="editor-field">
        @Html.EditorFor(model => model.DownloadDate)
        @Html.ValidationMessageFor(model => model.DownloadDate)
    </div>

    <div class="display-field"><input type="submit" value="Add" /></div>
}

<div>@Html.ActionLink("Back To Downloads", "Index")</div>

任何建议吗?

谢谢,
亚历克斯。

Thanks, Alex.

推荐答案

好吧,我终于想通了这一点,这是所有造成的,因为我命名的形式相同,我的模型文件字段的文件输入,因此模型粘合剂进行这种采摘并试图将发布文件直接绑定到这是抛出一个异常,因为该字符串不是二进制的二进制属性。

Ok I figured this out finally, It was all caused because I named the file input on the form the same as my models file field, so the model binder was picking this up and trying to bind the posted file directly to the binary property which was throwing an exception because the string was not binary.

因此​​,要解决这个问题,我只是添加到了我的创建操作方法:

So to fix it I simply added this to my create action method:

[HttpPost]
    [Authorize]
    public ActionResult Create([Bind(Exclude = "DownloadFile")] Download dl, HttpPostedFileBase DownloadFile)
    {

通过告诉模型绑定来排除它解决了这个问题的领域。

By telling the model binder to exclude the field it solved the problem.

谢谢,
亚历克斯。

Thanks, Alex.

编辑:这也可以很容易地通过使用视图模型来解决。

This could also easily be solved by using view models

这篇关于输入不是有效的Base-64串,因为它含有非基本64字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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