我需要使用mvc5验证服务器端的图像上传。我正在使用angularJS代码使用base64上传图像。如何验证图像。 这是我在视图中的图片上传代码代码..
在视图中
<div>
<span class="btn btn-primary" ng-show="!$flow.files.length" data-flow-btn id="Image" >Select image</span>
<span class="btn btn-info" ng-show="$flow.files.length" data-flow-btn id="Image" >Change</span>
<span class="btn btn-danger" ng-show="$flow.files.length" ng-click="$flow.cancel()" >Remove</span>
</div>
控制器中的
public ActionResult ValidationControl()
{
return View();
}
[HttpPost]
public ActionResult ValidationControl(IEnumerable<HttpPostedFileBase> file,ServerValidation model)
{
if (!ModelState.IsValid)
{
ViewBag.Name = model.UserName;
ViewBag.Email = model.Password ;
}
return View();
}
在模型中
public class ServerValidation
{
[Required(ErrorMessage = "Name is Required")]
public string UserName { get; set; }
[Required (ErrorMessage = "password is Required")]
public string Password { get; set; }
[Required(ErrorMessage = "Image is Required")]
public string Image { get; set; }
}