"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."My View code:
Expand|Select|Wrap|Line Numbers
- <%@ Page Title="register" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<blog.models.users>" %>
- <%@ Import Namespace="blog.Models" %>
- <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
- <%using(Html.BeginForm("register","users",FormMethod.Post,new{enctype="multipart/form-data"}))
- {%> <br />
- <input type="file" name="upic"/>
- <input type="submit" value="upload"/>
- <%}%>
- </asp:Content>
I use linq to SQL,not Entity Framework ,the controller code is:
Expand|Select|Wrap|Line Numbers
- [AcceptVerbs(HttpVerbs.Post)]
- public ActionResult register([Bind(Exclude = "file")]HttpPostedFileBase file, users u)
- {
- var v = db.users;
- var sna = Request.Form["name"];
- if (v.Count(d => d.name == sna) > 0)
- {
- ckn = 0;
- }
- if (ckn == 1 && sna !="")
- {
- //如果没错误,返回首页
- u.uid = SqlHelper.get_ID("users", "uid");
- u.rdate = DateTime.Now;
- u.ndate = DateTime.Now;
- u.pwd = SqlHelper.md5(u.pwd);
- u.jib = 2;
- u.psum = 0;
- file = Request.Files["upic"];
- Int32 len = file.ContentLength;
- u.pict = file.ContentType;
- byte[] photo = new byte[len];
- file.InputStream.Read(photo, 0, len);
- u.upic = photo;
- db.SubmitChanges();
- db.users.InsertOnSubmit(u);
- db.SubmitChanges();
- }
- }
What makes the error occur
And how do you resolve this problem?
Thanks for helping me!