Simplify.Web.Multipart is a package which provides multipart form view model and model binder for Simplify.Web web-framework.
public void Configuration(IApplicationBuilder app)
{
// ...existing code...
HttpModelHandler.RegisterModelBinder<HttpMultipartFormModelBinder>();
// ...existing code...
app.UseSimplifyWeb();
}
public void ConfigureServices(IServiceCollection services)
{
// ...existing code...
DIContainer.Current.RegisterHttpMultipartFormModelBinder();
// ...existing code...
}public class MyController : ControllerAsync<MultipartViewModel>
{
public override async Task<ControllerResponse> Invoke()
{
await ReadModelAsync();
Model.Files;
}
}Multipart files will be deserialized to the controller model on first model access
public class MyController : Controller<MultipartViewModel>
{
public override ControllerResponse Invoke()
{
Model.Files;
}
}Instead of searching through the Parameters list manually, you can bind the multipart form parameters to a strongly typed model the same way as for a regular query/form/JSON request. Inherit your model from MultipartModel (which exposes Files) and add your own properties:
public class UploadModel : MultipartModel
{
public string Title { get; set; }
public int Count { get; set; }
}The parameters are parsed into the model properties automatically (the same parser as Simplify.Web query/form binding is reused, so [BindProperty], [Exclude], [Format], IList<T> properties and validation attributes are all supported), while the uploaded files remain accessible via Model.Files:
public class MyController : Controller2<UploadModel>
{
public async Task<ControllerResponse> Invoke()
{
Model.Title; // bound from the "Title" multipart parameter
Model.Count; // bound from the "Count" multipart parameter
Model.Files; // uploaded files
}
}The legacy MultipartViewModel (which exposes the raw Parameters list) still works as before and now also inherits from MultipartModel.