1、model文件中添加:
[UIHint("Picture")]
public int PictureId { get; set; }
UIHint的定义位于using System.ComponentModel.DataAnnotations;
2、cshtml文件
<div class="inputs">
@Html.LabelFor(model => model.PictureId,"营业执照:")
@Html.EditorFor(model =>model.PictureId)
@Html.ValidationMessageFor(model=> model.PictureId)
</div>3、运行之后
上传文件之后,该图片文件会以二进制的形式存储到数据表picture中;
model.PictureId将会拿到该文件在picture表中的id值;
之后可以将该id值与相应的模块进行关联。
注意:上传文件控件必须登录后才能正确上传文件或图片.如果在没有登录的界面使用该控件,每次都会报出上传文件失败的信息。