File upload MVC

前端 未结 5 546
一个人的身影
一个人的身影 2020-12-16 02:55

With the following markup in my view:

5条回答
  •  长情又很酷
    2020-12-16 03:25

    Use HttpPostedFileBase as a parameter on your action. Also, add the AcceptVerb attribute is set to POST.

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Upload(HttpPostedFileBase image)
    {
        if ( image != null ) {
            // do something
        }
        return View();
    }
    

    This code is quite in the spirit/design of ASP.NET MVC.

提交回复
热议问题