File tree Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -17,22 +17,23 @@ public class HttpMultipartFormModelBinder : IModelBinder
1717 /// <param name="args">The <see cref="ModelBinderEventArgs{T}" /> instance containing the event data.</param>
1818 public void Bind < T > ( ModelBinderEventArgs < T > args )
1919 {
20- if ( args . Context . Request . ContentType . Contains ( "multipart/form-data" ) )
21- {
22- var multipartModelType = typeof ( MultipartViewModel ) ;
23- if ( typeof ( T ) != multipartModelType )
24- throw new ModelBindingException ( "For HTTP multipart form data model type should be: " + multipartModelType . Name ) ;
20+ if ( ! args . Context . Request . ContentType . Contains ( "multipart/form-data" ) )
21+ return ;
2522
26- var parser = new MultipartFormDataParser ( args . Context . Request . Body ) ;
27- var obj = Activator . CreateInstance < T > ( ) ;
23+ var multipartModelType = typeof ( MultipartViewModel ) ;
2824
29- var model = ( MultipartViewModel ) ( object ) obj ;
25+ if ( typeof ( T ) != multipartModelType )
26+ throw new ModelBindingException ( "For HTTP multipart form data model type should be: " + multipartModelType . Name ) ;
3027
31- model . Files = parser . Files ;
32- model . Parameters = parser . Parameters ;
28+ var parser = new MultipartFormDataParser ( args . Context . Request . Body ) ;
29+ var obj = Activator . CreateInstance < T > ( ) ;
3330
34- args . SetModel ( obj ) ;
35- }
31+ var model = ( MultipartViewModel ) ( object ) obj ;
32+
33+ model . Files = parser . Files ;
34+ model . Parameters = parser . Parameters ;
35+
36+ args . SetModel ( obj ) ;
3637 }
3738 }
3839}
Original file line number Diff line number Diff line change 11<Project Sdk =" Microsoft.NET.Sdk" >
22 <PropertyGroup >
33 <TargetFrameworks >netstandard2.0</TargetFrameworks >
4+ <LangVersion >8.0</LangVersion >
45 <Authors >Alexander Krylkov</Authors >
56 <Product >Simplify</Product >
67 <Description >Simplify.Web multipart form model binder</Description >
1213 <RepositoryType >GIT</RepositoryType >
1314 <PackageTags >Simplify.Web multipart</PackageTags >
1415 <PackageReleaseNotes >
16+ New
17+ * `IDIRegistrator` `HttpMultipartFormModelBinder` registration extension method (#3)
1518 Updates
16- * Upgrade to Simplify.Web 3
19+ * Upgrade to Simplify.Web 3 (PR #2)
1720 </PackageReleaseNotes >
1821 <OutputPath >bin\Any CPU\$(Configuration)\</OutputPath >
1922 <DocumentationFile >bin\Any CPU\$(Configuration)\$(TargetFramework)\Simplify.Web.Multipart.xml</DocumentationFile >
You can’t perform that action at this time.
0 commit comments