enums can also be strings (and numbers)

alphons <alphons@heijden.com> 14 May 2024, 16:55
21e69748e83c1259e77ba1b3a5f0340ffc1e0eb3
5 files changed
  • src/Mvc.ModelBinding.MultiParameter.Testing/Controllers/ComplexController.cs
  • src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/Default.js
  • src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/index.html
  • src/Mvc.ModelBinding.MultiParameter/GenericValueProvider.cs
  • src/Mvc.ModelBinding.MultiParameter/Mvc.ModelBinding.MultiParameter.csproj
diff --git a/src/Mvc.ModelBinding.MultiParameter.Testing/Controllers/ComplexController.cs b/src/Mvc.ModelBinding.MultiParameter.Testing/Controllers/ComplexController.cs
index 2192edc..c7f5f9f 100644
--- a/src/Mvc.ModelBinding.MultiParameter.Testing/Controllers/ComplexController.cs
+++ b/src/Mvc.ModelBinding.MultiParameter.Testing/Controllers/ComplexController.cs
@@ -4,560 +4,565 @@ using Microsoft.AspNetCore.Mvc.ModelBinding.MultiParameter;
#nullable disable
-namespace CoreBasic.Web.LogicControllers
+namespace CoreBasic.Web.LogicControllers;
+
+public class ComplexController : ControllerBase
{
- public class ComplexController : ControllerBase
- {
- [HttpGet]
- [Route("~/api/index")]
+ [HttpGet]
+ [Route("~/api/index")]
- // 1.0
- public async Task<IActionResult> Index(List<string> list)
- {
- await Task.Yield();
+ // 1.0
+ public async Task<IActionResult> Index(List<string> list)
+ {
+ await Task.Yield();
- // Using SomeValueProviderFactory
- // Returned list "a", b", "b", "c" <- repeat-bug
- // Expected list "a", b", null, "c"
+ // Using SomeValueProviderFactory
+ // Returned list "a", b", "b", "c" <- repeat-bug
+ // Expected list "a", b", null, "c"
- return Ok();
- }
+ return Ok();
+ }
- // 2.1
+ // 2.1
- [HttpPost]
- [Route("~/api/SimpleString1")]
- public async Task<IActionResult> SimpleString1(string user)
+ [HttpPost]
+ [Route("~/api/SimpleString1")]
+ public async Task<IActionResult> SimpleString1(string user)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- user
- });
- }
+ user
+ });
+ }
- [HttpPost]
- [Route("~/api/SimpleString2")]
- public async Task<IActionResult> SimpleString2([FromBody] string user)
+ [HttpPost]
+ [Route("~/api/SimpleString2")]
+ public async Task<IActionResult> SimpleString2([FromBody] string user)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- user
- });
- }
+ user
+ });
+ }
- public class ModelOfString
- {
- public string user { get; set; }
- }
+ public class ModelOfString
+ {
+ public string user { get; set; }
+ }
- [HttpPost]
- [Route("~/api/SimpleString3")]
- public async Task<IActionResult> SimpleString3(ModelOfString model)
+ [HttpPost]
+ [Route("~/api/SimpleString3")]
+ public async Task<IActionResult> SimpleString3(ModelOfString model)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- model?.user
- });
- }
+ model?.user
+ });
+ }
- [HttpPost]
- [Route("~/api/SimpleString4")]
- public async Task<IActionResult> SimpleString4([FromBody] ModelOfString model)
+ [HttpPost]
+ [Route("~/api/SimpleString4")]
+ public async Task<IActionResult> SimpleString4([FromBody] ModelOfString model)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- model?.user
- });
- }
+ model?.user
+ });
+ }
- // 2.2
- [HttpPost]
- [Route("~/api/ArrayOfStrings1")]
- public async Task<IActionResult> ArrayOfStrings1(List<string> users)
+ // 2.2
+ [HttpPost]
+ [Route("~/api/ArrayOfStrings1")]
+ public async Task<IActionResult> ArrayOfStrings1(List<string> users)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- users
- });
- }
+ users
+ });
+ }
- [HttpPost]
- [Route("~/api/ArrayOfStrings2")]
- public async Task<IActionResult> ArrayOfStrings2([FromBody] List<string> users)
+ [HttpPost]
+ [Route("~/api/ArrayOfStrings2")]
+ public async Task<IActionResult> ArrayOfStrings2([FromBody] List<string> users)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- users
- });
- }
+ users
+ });
+ }
- public class ModelArrayOfStrings
- {
- public List<string> users { get; set; }
- }
+ public class ModelArrayOfStrings
+ {
+ public List<string> users { get; set; }
+ }
- [HttpPost]
- [Route("~/api/ArrayOfStrings3")]
- public async Task<IActionResult> ArrayOfStrings3(ModelArrayOfStrings model)
+ [HttpPost]
+ [Route("~/api/ArrayOfStrings3")]
+ public async Task<IActionResult> ArrayOfStrings3(ModelArrayOfStrings model)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- model?.users
- });
- }
+ model?.users
+ });
+ }
- [HttpPost]
- [Route("~/api/ArrayOfStrings4")]
- public async Task<IActionResult> ArrayOfStrings4([FromBody] ModelArrayOfStrings model)
+ [HttpPost]
+ [Route("~/api/ArrayOfStrings4")]
+ public async Task<IActionResult> ArrayOfStrings4([FromBody] ModelArrayOfStrings model)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- model?.users
- });
- }
+ model?.users
+ });
+ }
- // 2.3
+ // 2.3
- public class ModelArrayOfArrayOfStrings
- {
- public List<List<string>> users { get; set; }
- }
+ public class ModelArrayOfArrayOfStrings
+ {
+ public List<List<string>> users { get; set; }
+ }
- [HttpPost]
- [Route("~/api/ArrayOfArrayOfStrings1")]
- public async Task<IActionResult> ArrayOfArrayOfStrings1(ModelArrayOfArrayOfStrings model)
+ [HttpPost]
+ [Route("~/api/ArrayOfArrayOfStrings1")]
+ public async Task<IActionResult> ArrayOfArrayOfStrings1(ModelArrayOfArrayOfStrings model)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- model?.users
- });
- }
+ model?.users
+ });
+ }
- [HttpPost]
- [Route("~/api/ArrayOfArrayOfStrings2")]
- public async Task<IActionResult> ArrayOfArrayOfStrings2([FromBody] ModelArrayOfArrayOfStrings model)
+ [HttpPost]
+ [Route("~/api/ArrayOfArrayOfStrings2")]
+ public async Task<IActionResult> ArrayOfArrayOfStrings2([FromBody] ModelArrayOfArrayOfStrings model)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- model?.users
- });
- }
+ model?.users
+ });
+ }
- [HttpPost]
- [Route("~/api/TwoParameters1")]
- public async Task<IActionResult> TwoParameters1(string a, string b)
+ [HttpPost]
+ [Route("~/api/TwoParameters1")]
+ public async Task<IActionResult> TwoParameters1(string a, string b)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- a,
- b
- });
- }
+ a,
+ b
+ });
+ }
- [HttpPost]
- [Route("~/api/TwoParameters2")]
- public async Task<IActionResult> TwoParameters2([FromBody] string a, string b)
+ [HttpPost]
+ [Route("~/api/TwoParameters2")]
+ public async Task<IActionResult> TwoParameters2([FromBody] string a, string b)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- a,b
- });
- }
+ a,b
+ });
+ }
- [HttpPost]
- [Route("~/api/TwoParameters3")]
- public async Task<IActionResult> TwoParameters3([FromBody] ModelOfString a, ModelOfString b)
+ [HttpPost]
+ [Route("~/api/TwoParameters3")]
+ public async Task<IActionResult> TwoParameters3([FromBody] ModelOfString a, ModelOfString b)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- a = a.user,
- b = b.user
- });
- }
+ a = a.user,
+ b = b.user
+ });
+ }
- // Solution 1, problem of the repeater bug
+ // Solution 1, problem of the repeater bug
- [HttpPost]
- [Route("~/api/ListOfDoubles")]
- public async Task<IActionResult> ListOfDoubles(List<double?> list)
+ [HttpPost]
+ [Route("~/api/ListOfDoubles")]
+ public async Task<IActionResult> ListOfDoubles(List<double?> list)
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
- list
- });
- }
+ list
+ });
+ }
- public class ApiModel
- {
- public string Name { get; set; }
- public List<List<Usert>> Users { get; set; }
+ public class ApiModel
+ {
+ public string Name { get; set; }
+ public List<List<Usert>> Users { get; set; }
- public override string ToString() => Name;
- }
+ public override string ToString() => Name;
+ }
- [HttpGet]
- [Route("~/api/HelloWorld")]
- public async Task<IActionResult> HelloWorld()
- {
- // Forces a session cooky
- HttpContext.Session.SetString("Hello", "World");
- await HttpContext.Session.CommitAsync();
+ [HttpGet]
+ [Route("~/api/HelloWorld")]
+ public async Task<IActionResult> HelloWorld()
+ {
+ // Forces a session cooky
+ HttpContext.Session.SetString("Hello", "World");
+ await HttpContext.Session.CommitAsync();
- return Ok();
- }
+ return Ok();
+ }
- [HttpPost]
- [Route("~/api/ComplexTest")]
- public async Task<IActionResult> ComplexTest(
- ApiModel SomeParameter4,
- string SomeParameter5)
+ [HttpPost]
+ [Route("~/api/ComplexTest")]
+ public async Task<IActionResult> ComplexTest(
+ ApiModel SomeParameter4,
+ string SomeParameter5)
+ {
+ await Task.Yield();
+
+ return Ok(new
{
- await Task.Yield();
- return Ok(new
- {
+ });
+ }
- });
- }
+ [HttpPost]
+ [Route("~/api/DemoProposal/{SomeParameter2}")]
+ public async Task<IActionResult> DemoProposal(
+ [FromCooky(Name = ".AspNetCore.Session")] string SomeParameter0,
+ [FromHeader(Name = "Referer")] string SomeParameter1,
+ [FromRoute] string SomeParameter2,
+ [FromQuery] string SomeParameter3,
+ [FromBody] ApiModel SomeParameter4,
+ [FromBody] string SomeParameter5,
+ [FromQuery]string SomeParameter6)
+ {
+ await Task.Yield();
+
+ return Ok(new
+ {
+ SomeParameter0,
+ SomeParameter1,
+ SomeParameter2,
+ SomeParameter3,
+ SomeParameter4,
+ SomeParameter5,
+ SomeParameter6
+ });
+ }
- [HttpPost]
- [Route("~/api/DemoProposal/{SomeParameter2}")]
- public async Task<IActionResult> DemoProposal(
- [FromCooky(Name = ".AspNetCore.Session")] string SomeParameter0,
- [FromHeader(Name = "Referer")] string SomeParameter1,
- [FromRoute] string SomeParameter2,
- [FromQuery] string SomeParameter3,
- [FromBody] ApiModel SomeParameter4,
- [FromBody] string SomeParameter5,
- [FromQuery]string SomeParameter6)
- {
- await Task.Yield();
-
- return Ok(new
- {
- SomeParameter0,
- SomeParameter1,
- SomeParameter2,
- SomeParameter3,
- SomeParameter4,
- SomeParameter5,
- SomeParameter6
- });
- }
+ [HttpPost]
+ [Route("~/api/DemoProposal2/{SomeParameter2}")]
+ public async Task<IActionResult> DemoProposal(
+ string Referer,
+ string SomeParameter2,
+ string SomeParameter3,
+ ApiModel SomeParameter4,
+ string SomeParameter5,
+ string SomeParameter6)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/DemoProposal2/{SomeParameter2}")]
- public async Task<IActionResult> DemoProposal(
- string Referer,
- string SomeParameter2,
- string SomeParameter3,
- ApiModel SomeParameter4,
- string SomeParameter5,
- string SomeParameter6)
- {
- await Task.Yield();
-
- return Ok(new
- {
- Referer,
- SomeParameter2,
- SomeParameter3,
- SomeParameter4,
- SomeParameter5,
- SomeParameter6
- });
- }
+ return Ok(new
+ {
+ Referer,
+ SomeParameter2,
+ SomeParameter3,
+ SomeParameter4,
+ SomeParameter5,
+ SomeParameter6
+ });
+ }
- [HttpPost]
- [Route("~/api/ComplexString")]
- public async Task<IActionResult> ComplexString(string Name)
+ [HttpPost]
+ [Route("~/api/ComplexString")]
+ public async Task<IActionResult> ComplexString(string Name)
+ {
+ await Task.Yield();
+
+ return Ok(new
{
- await Task.Yield();
+ Name
+ });
+ }
- return Ok(new
- {
- Name
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexDouble")]
+ public async Task<IActionResult> ComplexDouble(double? F)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexDouble")]
- public async Task<IActionResult> ComplexDouble(double? F)
+ return Ok(new
{
- await Task.Yield();
+ F
+ });
+ }
- return Ok(new
- {
- F
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexStringInt")]
+ public async Task<IActionResult> ComplexStringInt(string Name, int A)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexStringInt")]
- public async Task<IActionResult> ComplexStringInt(string Name, int A)
+ return Ok(new
{
- await Task.Yield();
+ Name,
+ A
+ });
+ }
- return Ok(new
- {
- Name,
- A
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexListOfStrings")]
+ public async Task<IActionResult> ComplexListOfStrings(List<string> ListOfStrings)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexListOfStrings")]
- public async Task<IActionResult> ComplexListOfStrings(List<string> ListOfStrings)
+ return Ok(new
{
- await Task.Yield();
+ ListOfStrings
+ });
+ }
- return Ok(new
- {
- ListOfStrings
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexListOfInts")]
+ public async Task<IActionResult> ComplexListOfInts(List<int?> ListOfInts)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexListOfInts")]
- public async Task<IActionResult> ComplexListOfInts(List<int?> ListOfInts)
+ return Ok(new
{
- await Task.Yield();
+ ListOfInts
+ });
+ }
- return Ok(new
- {
- ListOfInts
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexListNullableDouble")]
+ public async Task<IActionResult> ComplexListNullableDouble(List<double?> list)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexListNullableDouble")]
- public async Task<IActionResult> ComplexListNullableDouble(List<double?> list)
+ return Ok(new
{
- await Task.Yield();
+ list
+ });
+ }
- return Ok(new
- {
- list
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexListObjecs")]
+ public async Task<IActionResult> ComplexListObjecs(List<string> list)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexListObjecs")]
- public async Task<IActionResult> ComplexListObjecs(List<string> list)
+ return Ok(new
{
- await Task.Yield();
+ list
+ });
+ }
- return Ok(new
- {
- list
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexStringList")]
+ public async Task<IActionResult> ComplexStringList(string Name, List<string> list)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexStringList")]
- public async Task<IActionResult> ComplexStringList(string Name, List<string> list)
+ return Ok(new
{
- await Task.Yield();
+ Name,
+ list
+ });
+ }
- return Ok(new
- {
- Name,
- list
- });
- }
+ public class ObjectB
+ {
+ public List<ObjectA> List { get; set; }
- public class ObjectB
- {
- public List<ObjectA> List { get; set; }
+ public string Name { get;set;}
+ }
- public string Name { get;set;}
- }
+ public class ObjectA
+ {
+ public string a { get; set; }
+ public string b { get; set; }
+ }
- public class ObjectA
- {
- public string a { get; set; }
- public string b { get; set; }
- }
+ [HttpPost]
+ [Route("~/api/ComplexSingleObject")]
+ public async Task<IActionResult> ComplexSingleObject(ObjectA AA)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexSingleObject")]
- public async Task<IActionResult> ComplexSingleObject(ObjectA AA)
+ return Ok(new
{
- await Task.Yield();
+ AA
+ });
+ }
- return Ok(new
- {
- AA
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexArray")]
+ public async Task<IActionResult> ComplexArray(ObjectA[] list)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexArray")]
- public async Task<IActionResult> ComplexArray(ObjectA[] list)
+ return Ok(new
{
- await Task.Yield();
+ list
+ });
+ }
- return Ok(new
- {
- list
- });
- }
+ [HttpPost]
+ [Route("~/api/ComplexObjectArray")]
+ public async Task<IActionResult> ComplexObjectArray(ObjectB objB)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexObjectArray")]
- public async Task<IActionResult> ComplexObjectArray(ObjectB objB)
+ return Ok(new
{
- await Task.Yield();
+ objB
+ });
+ }
- return Ok(new
- {
- objB
- });
- }
+ public class ObjectC
+ {
+ public string Name { get; set; }
+ public List<List<string>> Users { get; set; }
+ }
- public class ObjectC
- {
- public string Name { get; set; }
- public List<List<string>> Users { get; set; }
- }
+ [HttpPost]
+ [Route("~/api/ComplexArrayArray")]
+ public async Task<IActionResult> ComplexArrayArray(string Group, ObjectC List)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexArrayArray")]
- public async Task<IActionResult> ComplexArrayArray(string Group, ObjectC List)
+ return Ok(new
{
- await Task.Yield();
+ Group,
+ List
+ });
+ }
- return Ok(new
- {
- Group,
- List
- });
- }
+ public class Usert
+ {
+ public string Name { get; set; }
- public class Usert
- {
- public string Name { get; set; }
+ public List<string> Alias { get; set; }
+ }
- public List<string> Alias { get; set; }
- }
+ public class ObjectD
+ {
+ public string Name { get; set; }
+ public List<List<Usert>> Users { get; set; }
+ }
- public class ObjectD
- {
- public string Name { get; set; }
- public List<List<Usert>> Users { get; set; }
- }
+ [HttpPost]
+ [Route("~/api/ComplexArrayArrayClass")]
+ public async Task<IActionResult> ComplexArrayArrayClass(bool Testing, bool Relaxed, string Group, ObjectD GroupInfo)
+ {
+ await Task.Yield();
- [HttpPost]
- [Route("~/api/ComplexArrayArrayClass")]
- public async Task<IActionResult> ComplexArrayArrayClass(bool Testing, bool Relaxed, string Group, ObjectD GroupInfo)
+ return Ok(new
{
- await Task.Yield();
-
- return Ok(new
- {
- Testing,
- Relaxed,
- Group,
- GroupInfo
- });
- }
-
+ Testing,
+ Relaxed,
+ Group,
+ GroupInfo
+ });
+ }
- /// <summary>
- /// Uploads have default a maximum of 30MByte presenting upload example of 2.5GB
- ///
- /// For IIS Limit maxAllowedContentLength in Web.config (in the root of the app, not in wwwroot content folder!)
- ///
- /// </summary>
- /// <param name="formFile"></param>
- /// <returns></returns>
- [HttpPost]
- [Route("~/api/Upload")]
- [RequestSizeLimit(2_500_000_000)]
- [RequestFormLimits(MultipartBodyLengthLimit = 2_500_000_000)]
- public async Task<IActionResult> Upload(IFormFile file, string Form1)
- {
- long Length = -1;
- if (file != null && file.Length > 0)
- {
- Length = file.Length;
- using var ms = new MemoryStream();
- await file.CopyToAsync(ms); // some dummy operation
- }
- return Ok(new
- {
- Length,
- Form1
- });
- }
- public enum AddressEnum
+ /// <summary>
+ /// Uploads have default a maximum of 30MByte presenting upload example of 2.5GB
+ ///
+ /// For IIS Limit maxAllowedContentLength in Web.config (in the root of the app, not in wwwroot content folder!)
+ ///
+ /// </summary>
+ /// <param name="formFile"></param>
+ /// <returns></returns>
+ [HttpPost]
+ [Route("~/api/Upload")]
+ [RequestSizeLimit(2_500_000_000)]
+ [RequestFormLimits(MultipartBodyLengthLimit = 2_500_000_000)]
+ public async Task<IActionResult> Upload(IFormFile file, string Form1)
+ {
+ long Length = -1;
+ if (file != null && file.Length > 0)
{
- Unknown,
- Living,
- Working
+ Length = file.Length;
+ using var ms = new MemoryStream();
+ await file.CopyToAsync(ms); // some dummy operation
}
-
- public enum StatusEnum
+ return Ok(new
{
- Unknown,
- Active,
- Passive
- }
+ Length,
+ Form1
+ });
+ }
- [HttpGet]
- [Route("~/api/GetEnums")]
- public async Task<IActionResult> GetEnums()
- {
- await Task.Yield();
- return Ok(new
- {
- StatusEnum.Active,
- AddressEnum.Working
- });
- }
+ public enum AddressEnum
+ {
+ Unknown,
+ Living,
+ Working
+ }
- public class Product
- {
- public StatusEnum StatusType { get; set; }
- public AddressEnum AddressType { get; set; }
- }
+ public enum StatusEnum
+ {
+ Unknown,
+ Active,
+ Passive
+ }
- [HttpPost]
- [Route("~/api/PostEnum")]
- public async Task<IActionResult> PostEnum(StatusEnum status)
+ [HttpGet]
+ [Route("~/api/GetEnums")]
+ public async Task<IActionResult> GetEnums()
+ {
+ await Task.Yield();
+ return Ok(new
{
- await Task.Yield();
- return Ok();
- }
+ StatusEnum.Active,
+ AddressEnum.Working
+ });
+ }
- [HttpPost]
- [Route("~/api/PostEnums")]
- public async Task<IActionResult> PostEnums(Product product)
- {
- await Task.Yield();
- return Ok();
- }
+ public class Product
+ {
+ public StatusEnum StatusType { get; set; }
+ public AddressEnum AddressType { get; set; }
+ }
+
+ [HttpPost]
+ [Route("~/api/PostEnum")]
+ public async Task<IActionResult> PostEnum(StatusEnum status)
+ {
+ await Task.Yield();
+ return Ok();
+ }
+ [HttpPost]
+ [Route("~/api/PostEnums")]
+ public async Task<IActionResult> PostEnums(Product product)
+ {
+ await Task.Yield();
+ return Ok();
+ }
+
+ [HttpPost("~/api/PostEnumAsString")]
+ public async Task<IActionResult> PostEnumAsString(StatusEnum status)
+ {
+ await Task.Yield();
+ return Ok(true);
}
}
diff --git a/src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/Default.js b/src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/Default.js
index b2c5014..edbd2f2 100644
--- a/src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/Default.js
+++ b/src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/Default.js
@@ -310,3 +310,9 @@ async function MultiBinderTest()
$id("Result").innerText += ' other alias: ' + result2.SomeParameter4.Users[0][0].Alias[2];
}
+
+
+async function PostEnumAsString()
+{
+ var result = await netproxyasync("./api/PostEnumAsString", { status : 'Active' });
+}
diff --git a/src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/index.html b/src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/index.html
index 39867df..6769722 100644
--- a/src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/index.html
+++ b/src/Mvc.ModelBinding.MultiParameter.Testing/wwwroot/index.html
@@ -27,6 +27,8 @@
<div><span id="MultiBinderTest" class="ui-btn">MultiBinderTest</span></div>
+ <div><span id="PostEnumAsString" class="ui-btn">Post Enum As String</span></div>
+
<img src="images/netproxyspinner.gif" id="netproxyspinner" />
</body>
</html>
diff --git a/src/Mvc.ModelBinding.MultiParameter/GenericValueProvider.cs b/src/Mvc.ModelBinding.MultiParameter/GenericValueProvider.cs
index 9159e7a..a9b861a 100644
--- a/src/Mvc.ModelBinding.MultiParameter/GenericValueProvider.cs
+++ b/src/Mvc.ModelBinding.MultiParameter/GenericValueProvider.cs
@@ -65,7 +65,13 @@ public class GenericValueProvider : BindingSourceValueProvider
this.jsonDocument.RootElement.TryGetProperty(key, out JsonElement prop))
{
// this needs some tweaking!!!
- if (prop.ValueKind != JsonValueKind.Array || t.IsArray || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>)))
+ if (t.IsEnum && prop.ValueKind == JsonValueKind.String)
+ {
+ _ = Enum.TryParse(t, prop.GetString(), out object? result);
+
+ return result;
+ }
+ else if (prop.ValueKind != JsonValueKind.Array || t.IsArray || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>)))
{
return prop.Deserialize(t, this.jsonSerializerOptions);
}
diff --git a/src/Mvc.ModelBinding.MultiParameter/Mvc.ModelBinding.MultiParameter.csproj b/src/Mvc.ModelBinding.MultiParameter/Mvc.ModelBinding.MultiParameter.csproj
index 6397a41..cd1e182 100644
--- a/src/Mvc.ModelBinding.MultiParameter/Mvc.ModelBinding.MultiParameter.csproj
+++ b/src/Mvc.ModelBinding.MultiParameter/Mvc.ModelBinding.MultiParameter.csproj
@@ -10,11 +10,11 @@
<RepositoryUrl>https://github.com/alphons/Mvc.ModelBinding.MultiParameter.git</RepositoryUrl>
<Description>New ValueProviders and ModelBinder for multi parameters model binding out of the box on AspNetCore</Description>
<PackageDescription>New ValueProviders and ModelBinder for multi parameters model binding out of the box on AspNetCore</PackageDescription>
- <Version>1.1.8</Version>
+ <Version>1.1.9</Version>
<PackageId>Mvc.ModelBinding.MultiParameter</PackageId>
<Authors>alphons</Authors>
- <AssemblyVersion>8.0.1.0</AssemblyVersion>
- <FileVersion>8.0.1.0</FileVersion>
+ <AssemblyVersion>8.0.1.9</AssemblyVersion>
+ <FileVersion>8.0.1.9</FileVersion>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<PackageTags>Microsoft;AspNetCore;Mvc;AspNetCoreMvc;json</PackageTags>
<PackageIcon>icon.png</PackageIcon>