C# ASP.NET base64输入无效。输入不是有效的Base-64字符串

C# ASP.NET base64输入无效。输入不是有效的Base-64字符串,c#,asp.net-mvc,model-view-controller,razor,httppostedfilebase,C#,Asp.net Mvc,Model View Controller,Razor,Httppostedfilebase,我试图上传一张照片到我的控制器,但它显示了这个错误。但是,另一个页面可以正常工作。我可以问一下为什么吗?下面是我的查看代码 @using (Html.BeginForm("ManageProfile", "Owner", FormMethod.Post, new { enctype = "multipart/form-data" })) { <input type="file" id="profil

我试图上传一张照片到我的控制器,但它显示了这个错误。但是,另一个页面可以正常工作。我可以问一下为什么吗?下面是我的查看代码

@using (Html.BeginForm("ManageProfile", "Owner", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
 <input type="file" id="profilePic" name="profilePic" />
}
另一个控制器工作正常

<div class="form-group">
                    @Html.LabelFor(model => model.photo3, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        <input type="file" id="photoupload3" name="photoupload3" />
                        <img id="photo3"  style="max-height:300px;max-width:300px;" />
                    </div>
                </div>
堆栈跟踪

查看完整代码

@使用(Html.BeginForm(“ManageProfile”,“Owner”,FormMethod.Post,new{enctype=“multipart/formdata”}))
{
@Html.AntiForgeryToken()
所有者

@Html.ValidationSummary(true,“,new{@class=“text danger”}) @Html.HiddenFor(model=>model.ownerID) @LabelFor(model=>model.Name,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Name,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Name,“,new{@class=“text danger”}) @LabelFor(model=>model.contact,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.contact,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.contact,“,new{@class=“text danger”}) @LabelFor(model=>model.email,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.email,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.email,“,new{@class=“text danger”}) @LabelFor(model=>model.password,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.password,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.password,“,new{@class=“text danger”}) @*@LabelFor(model=>model.profilePic,htmlAttributes:new{@class=“controllabel col-md-2”})*@ @{ 如果(Model.profilePic!=null) { var base64=Convert.ToBase64String(Model.profilePic); var imgsrc=string.Format(“数据:image/gif;base64,{0}”,base64); } } }
出现了什么错误?哪一行代码出现故障?你是如何创建base64编码字符串的?它实际上看起来是无效的吗?我甚至不知道,控制器中的调试没有显示任何内容,事实上它没有进入控制器函数。我做的另一个页面与此完全相同,它期望的所有者控件在哪里我在这里看不到,你是根据某个id进行查询的…哪一行抛出了错误?我在帖子中更新了,你在图片中看到了,没有显示任何行抛出异常
[HttpPost]
        public ActionResult ManageProfile(Owner owner, HttpPostedFileBase profilePic)
        {
            string name = HttpContext.User.Identity.Name;
            var dbOwner = _context.OwnerDB.Find(owner.ownerID);
            dbOwner.contact = owner.contact;
            dbOwner.email = owner.email;
            dbOwner.Name = owner.Name;
            dbOwner.password = owner.password;
            if (profilePic != null)
            {
                dbOwner.profilePic = new byte[profilePic.ContentLength];
                profilePic.InputStream.Read(dbOwner.profilePic, 0, profilePic.ContentLength);
            }
            _context.SaveChanges();
            return RedirectToAction("Index","Home",null);
        }
[HttpPost]
        public ActionResult NewRoom(Room room, HttpPostedFileBase photoupload, HttpPostedFileBase photoupload2, HttpPostedFileBase photoupload3)
        {
            var ownerName = HttpContext.User.Identity.Name.ToString();
            Owner owner = _context.OwnerDB.Where(o => o.Name == ownerName).FirstOrDefault();
            room.ownerID = owner.ownerID;
            if (photoupload != null)
            {
                room.photo1 = new byte[photoupload.ContentLength];
                photoupload.InputStream.Read(room.photo1, 0, photoupload.ContentLength);
            }
@using (Html.BeginForm("ManageProfile", "Owner", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Owner</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.ownerID)

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.contact, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.contact, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.contact, "", new { @class = "text-danger" })
            </div>
        </div>



        <div class="form-group">
            @Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @*@Html.LabelFor(model => model.profilePic, htmlAttributes: new { @class = "control-label col-md-2" })*@
            <div class="col-md-10">

                <div class="col-md-10">
                    @{
                        if (Model.profilePic != null)
                        {
                            var base64 = Convert.ToBase64String(Model.profilePic);
                            var imgsrc = string.Format("data:image/gif;base64,{0}", base64);


                            <img src='@imgsrc' width="300" height="300" class="reel"
                                 data-image='@imgsrc'
                                 data-stitched="600"
                                 data-frames="30"
                                 data-frame="15"
                                 data-rows="1"
                                 data-row="1"
                                 data-loops="false"
                                 alt="@Model.Name" />
                        }

                    }

                    <input type="file" id="profilePic" name="profilePic" />
                </div>
            </div>
        </div>


        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}