Generate file upload input for property with “DataType.Upload” attribute?

后端 未结 3 1456
野趣味
野趣味 2021-01-07 05:50

I have the following view model.

public class MyViewModel
{
    [DataType(DataType.Upload)]
    public HttpPostedFileBase ImageUpload { get; set; }

    publ         


        
3条回答
  •  孤独总比滥情好
    2021-01-07 05:59

    How about getting rid of the HttpPostedFileBase from the model and adding it to the controller as a second parameter.

    In your html, you would add:

    
    

    In your controller you would do:

    [HttpPost]
    public ActionResult thisController(Model myModel, HttpPostedFileBase file)
    { }
    

    This should automatically catch any file you input.

提交回复
热议问题