Controller action with multiple parameters












1















I am trying to understand what I think is a model binding problem in my ASP.NET Core project. I have the following 'Index' controller action:



[HttpGet]
public async Task<IActionResult> Index(SortFilterIndexOptions options) { ... }


The SortFilterIndexOptions are four members defined in the following class:



public class SortFilterIndexOptions
{
public int SelectedBirdId { get; set; }
public bool ShowAll { get; set; }
public bool ShowInTable { get; set; }
public int page { get; set; }
}


These enable the user to filter a paged index page. The bool members are linked to checkbox controls.



I have a fault if the 'ShowAll' bool member is changed to TRUE and then try to navigate to a different page. As the screenshot, below, shows the 'ShowAll' parameter part of the url then contains two bool values ('ShowAll=true, false'):



enter image description here



which of course results in a parse error ('FormatException: String was not recognized as a valid Boolean').



What's happening here? It only happens when the 'ShowAll' parameter is toggled to TRUE. Is it a routing problem because it does not follow the default route pattern? Or is it a problem with the ModelBinder? I am just trying to understand what is going on so I can take the right action. Any help would be appreciated...



Update



This is now issue #3246 ('ModelBinding error with boolean values') on the asp/Home GitHub repository (originally raised by me as issue #1711 on the dotnet/Core repository).










share|improve this question

























  • The error message is pretty clear...ShowAll=true,false is not valid as a boolean. Should work with just ShowAll=true

    – Nkosi
    May 16 '18 at 10:34













  • Is this a checkbox in a form which is sent through GET?

    – CodeCaster
    May 16 '18 at 10:41






  • 1





    Yes, I am trying to work out why it adding the two Boolean values. When I click the next page button. This happens the ShowAll is toggled to true. Why is it appending the second ‘false’ value in the url?

    – Winthorpe
    May 16 '18 at 10:43











  • @CodeCaster. It is a Bootstrap Toggle control. So the same as a checkbox. In a form to a GET

    – Winthorpe
    May 16 '18 at 10:44


















1















I am trying to understand what I think is a model binding problem in my ASP.NET Core project. I have the following 'Index' controller action:



[HttpGet]
public async Task<IActionResult> Index(SortFilterIndexOptions options) { ... }


The SortFilterIndexOptions are four members defined in the following class:



public class SortFilterIndexOptions
{
public int SelectedBirdId { get; set; }
public bool ShowAll { get; set; }
public bool ShowInTable { get; set; }
public int page { get; set; }
}


These enable the user to filter a paged index page. The bool members are linked to checkbox controls.



I have a fault if the 'ShowAll' bool member is changed to TRUE and then try to navigate to a different page. As the screenshot, below, shows the 'ShowAll' parameter part of the url then contains two bool values ('ShowAll=true, false'):



enter image description here



which of course results in a parse error ('FormatException: String was not recognized as a valid Boolean').



What's happening here? It only happens when the 'ShowAll' parameter is toggled to TRUE. Is it a routing problem because it does not follow the default route pattern? Or is it a problem with the ModelBinder? I am just trying to understand what is going on so I can take the right action. Any help would be appreciated...



Update



This is now issue #3246 ('ModelBinding error with boolean values') on the asp/Home GitHub repository (originally raised by me as issue #1711 on the dotnet/Core repository).










share|improve this question

























  • The error message is pretty clear...ShowAll=true,false is not valid as a boolean. Should work with just ShowAll=true

    – Nkosi
    May 16 '18 at 10:34













  • Is this a checkbox in a form which is sent through GET?

    – CodeCaster
    May 16 '18 at 10:41






  • 1





    Yes, I am trying to work out why it adding the two Boolean values. When I click the next page button. This happens the ShowAll is toggled to true. Why is it appending the second ‘false’ value in the url?

    – Winthorpe
    May 16 '18 at 10:43











  • @CodeCaster. It is a Bootstrap Toggle control. So the same as a checkbox. In a form to a GET

    – Winthorpe
    May 16 '18 at 10:44
















1












1








1


0






I am trying to understand what I think is a model binding problem in my ASP.NET Core project. I have the following 'Index' controller action:



[HttpGet]
public async Task<IActionResult> Index(SortFilterIndexOptions options) { ... }


The SortFilterIndexOptions are four members defined in the following class:



public class SortFilterIndexOptions
{
public int SelectedBirdId { get; set; }
public bool ShowAll { get; set; }
public bool ShowInTable { get; set; }
public int page { get; set; }
}


These enable the user to filter a paged index page. The bool members are linked to checkbox controls.



I have a fault if the 'ShowAll' bool member is changed to TRUE and then try to navigate to a different page. As the screenshot, below, shows the 'ShowAll' parameter part of the url then contains two bool values ('ShowAll=true, false'):



enter image description here



which of course results in a parse error ('FormatException: String was not recognized as a valid Boolean').



What's happening here? It only happens when the 'ShowAll' parameter is toggled to TRUE. Is it a routing problem because it does not follow the default route pattern? Or is it a problem with the ModelBinder? I am just trying to understand what is going on so I can take the right action. Any help would be appreciated...



Update



This is now issue #3246 ('ModelBinding error with boolean values') on the asp/Home GitHub repository (originally raised by me as issue #1711 on the dotnet/Core repository).










share|improve this question
















I am trying to understand what I think is a model binding problem in my ASP.NET Core project. I have the following 'Index' controller action:



[HttpGet]
public async Task<IActionResult> Index(SortFilterIndexOptions options) { ... }


The SortFilterIndexOptions are four members defined in the following class:



public class SortFilterIndexOptions
{
public int SelectedBirdId { get; set; }
public bool ShowAll { get; set; }
public bool ShowInTable { get; set; }
public int page { get; set; }
}


These enable the user to filter a paged index page. The bool members are linked to checkbox controls.



I have a fault if the 'ShowAll' bool member is changed to TRUE and then try to navigate to a different page. As the screenshot, below, shows the 'ShowAll' parameter part of the url then contains two bool values ('ShowAll=true, false'):



enter image description here



which of course results in a parse error ('FormatException: String was not recognized as a valid Boolean').



What's happening here? It only happens when the 'ShowAll' parameter is toggled to TRUE. Is it a routing problem because it does not follow the default route pattern? Or is it a problem with the ModelBinder? I am just trying to understand what is going on so I can take the right action. Any help would be appreciated...



Update



This is now issue #3246 ('ModelBinding error with boolean values') on the asp/Home GitHub repository (originally raised by me as issue #1711 on the dotnet/Core repository).







c# asp.net-core asp.net-core-routing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 0:27









abatishchev

69.8k70263396




69.8k70263396










asked May 16 '18 at 7:44









WinthorpeWinthorpe

95215




95215













  • The error message is pretty clear...ShowAll=true,false is not valid as a boolean. Should work with just ShowAll=true

    – Nkosi
    May 16 '18 at 10:34













  • Is this a checkbox in a form which is sent through GET?

    – CodeCaster
    May 16 '18 at 10:41






  • 1





    Yes, I am trying to work out why it adding the two Boolean values. When I click the next page button. This happens the ShowAll is toggled to true. Why is it appending the second ‘false’ value in the url?

    – Winthorpe
    May 16 '18 at 10:43











  • @CodeCaster. It is a Bootstrap Toggle control. So the same as a checkbox. In a form to a GET

    – Winthorpe
    May 16 '18 at 10:44





















  • The error message is pretty clear...ShowAll=true,false is not valid as a boolean. Should work with just ShowAll=true

    – Nkosi
    May 16 '18 at 10:34













  • Is this a checkbox in a form which is sent through GET?

    – CodeCaster
    May 16 '18 at 10:41






  • 1





    Yes, I am trying to work out why it adding the two Boolean values. When I click the next page button. This happens the ShowAll is toggled to true. Why is it appending the second ‘false’ value in the url?

    – Winthorpe
    May 16 '18 at 10:43











  • @CodeCaster. It is a Bootstrap Toggle control. So the same as a checkbox. In a form to a GET

    – Winthorpe
    May 16 '18 at 10:44



















The error message is pretty clear...ShowAll=true,false is not valid as a boolean. Should work with just ShowAll=true

– Nkosi
May 16 '18 at 10:34







The error message is pretty clear...ShowAll=true,false is not valid as a boolean. Should work with just ShowAll=true

– Nkosi
May 16 '18 at 10:34















Is this a checkbox in a form which is sent through GET?

– CodeCaster
May 16 '18 at 10:41





Is this a checkbox in a form which is sent through GET?

– CodeCaster
May 16 '18 at 10:41




1




1





Yes, I am trying to work out why it adding the two Boolean values. When I click the next page button. This happens the ShowAll is toggled to true. Why is it appending the second ‘false’ value in the url?

– Winthorpe
May 16 '18 at 10:43





Yes, I am trying to work out why it adding the two Boolean values. When I click the next page button. This happens the ShowAll is toggled to true. Why is it appending the second ‘false’ value in the url?

– Winthorpe
May 16 '18 at 10:43













@CodeCaster. It is a Bootstrap Toggle control. So the same as a checkbox. In a form to a GET

– Winthorpe
May 16 '18 at 10:44







@CodeCaster. It is a Bootstrap Toggle control. So the same as a checkbox. In a form to a GET

– Winthorpe
May 16 '18 at 10:44














2 Answers
2






active

oldest

votes


















2














The error message is pretty clear...ShowAll=true,false is not valid as a Boolean.



The model binder is receiving the following string "true,false" from the query string for that parameter and would then try to parse that as a Boolean, which would fail as you have already seen.



Similar to trying



bool value = bool.Parse("true,false");


Should work with just ShowAll=true






share|improve this answer





















  • 1





    "When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'"

    – CodeCaster
    May 16 '18 at 10:41








  • 1





    @CodeCaster I am wondering now if the model binder in core has that capability?

    – Nkosi
    May 16 '18 at 10:47











  • Well I know core likes to break a lot of things, but something as fundamental as a checkbox on a form...?

    – CodeCaster
    May 16 '18 at 10:54











  • Yes it seems odd. I will change to a drop down list of enumerated values and see if it works. To try to see if the fault is isolated to the checkbox... As I mentioned, one can navigate the different pages of the checkboxes are left as false. It breaks when one is switched to true...

    – Winthorpe
    May 16 '18 at 11:08








  • 1





    I replaced the checkboxes with drop down lists and the model binding issue was resolved. Which suggests the issue was caused by the ModelBinder with checkboxes. I will leave the question open for a bit to see if anyone can add anything...

    – Winthorpe
    May 16 '18 at 16:27



















0














This issue was investigated by the aspnet/Mvc team under issue #8043.



There is no problem with the ModelBinder. The problem was caused by my pager code, which constructs the url. Please use the link to view the full conversation which contains a detailed explanation from the aspnet/Mvc team and sample code provided by me.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50365051%2fcontroller-action-with-multiple-parameters%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The error message is pretty clear...ShowAll=true,false is not valid as a Boolean.



    The model binder is receiving the following string "true,false" from the query string for that parameter and would then try to parse that as a Boolean, which would fail as you have already seen.



    Similar to trying



    bool value = bool.Parse("true,false");


    Should work with just ShowAll=true






    share|improve this answer





















    • 1





      "When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'"

      – CodeCaster
      May 16 '18 at 10:41








    • 1





      @CodeCaster I am wondering now if the model binder in core has that capability?

      – Nkosi
      May 16 '18 at 10:47











    • Well I know core likes to break a lot of things, but something as fundamental as a checkbox on a form...?

      – CodeCaster
      May 16 '18 at 10:54











    • Yes it seems odd. I will change to a drop down list of enumerated values and see if it works. To try to see if the fault is isolated to the checkbox... As I mentioned, one can navigate the different pages of the checkboxes are left as false. It breaks when one is switched to true...

      – Winthorpe
      May 16 '18 at 11:08








    • 1





      I replaced the checkboxes with drop down lists and the model binding issue was resolved. Which suggests the issue was caused by the ModelBinder with checkboxes. I will leave the question open for a bit to see if anyone can add anything...

      – Winthorpe
      May 16 '18 at 16:27
















    2














    The error message is pretty clear...ShowAll=true,false is not valid as a Boolean.



    The model binder is receiving the following string "true,false" from the query string for that parameter and would then try to parse that as a Boolean, which would fail as you have already seen.



    Similar to trying



    bool value = bool.Parse("true,false");


    Should work with just ShowAll=true






    share|improve this answer





















    • 1





      "When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'"

      – CodeCaster
      May 16 '18 at 10:41








    • 1





      @CodeCaster I am wondering now if the model binder in core has that capability?

      – Nkosi
      May 16 '18 at 10:47











    • Well I know core likes to break a lot of things, but something as fundamental as a checkbox on a form...?

      – CodeCaster
      May 16 '18 at 10:54











    • Yes it seems odd. I will change to a drop down list of enumerated values and see if it works. To try to see if the fault is isolated to the checkbox... As I mentioned, one can navigate the different pages of the checkboxes are left as false. It breaks when one is switched to true...

      – Winthorpe
      May 16 '18 at 11:08








    • 1





      I replaced the checkboxes with drop down lists and the model binding issue was resolved. Which suggests the issue was caused by the ModelBinder with checkboxes. I will leave the question open for a bit to see if anyone can add anything...

      – Winthorpe
      May 16 '18 at 16:27














    2












    2








    2







    The error message is pretty clear...ShowAll=true,false is not valid as a Boolean.



    The model binder is receiving the following string "true,false" from the query string for that parameter and would then try to parse that as a Boolean, which would fail as you have already seen.



    Similar to trying



    bool value = bool.Parse("true,false");


    Should work with just ShowAll=true






    share|improve this answer















    The error message is pretty clear...ShowAll=true,false is not valid as a Boolean.



    The model binder is receiving the following string "true,false" from the query string for that parameter and would then try to parse that as a Boolean, which would fail as you have already seen.



    Similar to trying



    bool value = bool.Parse("true,false");


    Should work with just ShowAll=true







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 16 '18 at 10:45

























    answered May 16 '18 at 10:38









    NkosiNkosi

    116k16130194




    116k16130194








    • 1





      "When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'"

      – CodeCaster
      May 16 '18 at 10:41








    • 1





      @CodeCaster I am wondering now if the model binder in core has that capability?

      – Nkosi
      May 16 '18 at 10:47











    • Well I know core likes to break a lot of things, but something as fundamental as a checkbox on a form...?

      – CodeCaster
      May 16 '18 at 10:54











    • Yes it seems odd. I will change to a drop down list of enumerated values and see if it works. To try to see if the fault is isolated to the checkbox... As I mentioned, one can navigate the different pages of the checkboxes are left as false. It breaks when one is switched to true...

      – Winthorpe
      May 16 '18 at 11:08








    • 1





      I replaced the checkboxes with drop down lists and the model binding issue was resolved. Which suggests the issue was caused by the ModelBinder with checkboxes. I will leave the question open for a bit to see if anyone can add anything...

      – Winthorpe
      May 16 '18 at 16:27














    • 1





      "When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'"

      – CodeCaster
      May 16 '18 at 10:41








    • 1





      @CodeCaster I am wondering now if the model binder in core has that capability?

      – Nkosi
      May 16 '18 at 10:47











    • Well I know core likes to break a lot of things, but something as fundamental as a checkbox on a form...?

      – CodeCaster
      May 16 '18 at 10:54











    • Yes it seems odd. I will change to a drop down list of enumerated values and see if it works. To try to see if the fault is isolated to the checkbox... As I mentioned, one can navigate the different pages of the checkboxes are left as false. It breaks when one is switched to true...

      – Winthorpe
      May 16 '18 at 11:08








    • 1





      I replaced the checkboxes with drop down lists and the model binding issue was resolved. Which suggests the issue was caused by the ModelBinder with checkboxes. I will leave the question open for a bit to see if anyone can add anything...

      – Winthorpe
      May 16 '18 at 16:27








    1




    1





    "When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'"

    – CodeCaster
    May 16 '18 at 10:41







    "When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'"

    – CodeCaster
    May 16 '18 at 10:41






    1




    1





    @CodeCaster I am wondering now if the model binder in core has that capability?

    – Nkosi
    May 16 '18 at 10:47





    @CodeCaster I am wondering now if the model binder in core has that capability?

    – Nkosi
    May 16 '18 at 10:47













    Well I know core likes to break a lot of things, but something as fundamental as a checkbox on a form...?

    – CodeCaster
    May 16 '18 at 10:54





    Well I know core likes to break a lot of things, but something as fundamental as a checkbox on a form...?

    – CodeCaster
    May 16 '18 at 10:54













    Yes it seems odd. I will change to a drop down list of enumerated values and see if it works. To try to see if the fault is isolated to the checkbox... As I mentioned, one can navigate the different pages of the checkboxes are left as false. It breaks when one is switched to true...

    – Winthorpe
    May 16 '18 at 11:08







    Yes it seems odd. I will change to a drop down list of enumerated values and see if it works. To try to see if the fault is isolated to the checkbox... As I mentioned, one can navigate the different pages of the checkboxes are left as false. It breaks when one is switched to true...

    – Winthorpe
    May 16 '18 at 11:08






    1




    1





    I replaced the checkboxes with drop down lists and the model binding issue was resolved. Which suggests the issue was caused by the ModelBinder with checkboxes. I will leave the question open for a bit to see if anyone can add anything...

    – Winthorpe
    May 16 '18 at 16:27





    I replaced the checkboxes with drop down lists and the model binding issue was resolved. Which suggests the issue was caused by the ModelBinder with checkboxes. I will leave the question open for a bit to see if anyone can add anything...

    – Winthorpe
    May 16 '18 at 16:27













    0














    This issue was investigated by the aspnet/Mvc team under issue #8043.



    There is no problem with the ModelBinder. The problem was caused by my pager code, which constructs the url. Please use the link to view the full conversation which contains a detailed explanation from the aspnet/Mvc team and sample code provided by me.






    share|improve this answer




























      0














      This issue was investigated by the aspnet/Mvc team under issue #8043.



      There is no problem with the ModelBinder. The problem was caused by my pager code, which constructs the url. Please use the link to view the full conversation which contains a detailed explanation from the aspnet/Mvc team and sample code provided by me.






      share|improve this answer


























        0












        0








        0







        This issue was investigated by the aspnet/Mvc team under issue #8043.



        There is no problem with the ModelBinder. The problem was caused by my pager code, which constructs the url. Please use the link to view the full conversation which contains a detailed explanation from the aspnet/Mvc team and sample code provided by me.






        share|improve this answer













        This issue was investigated by the aspnet/Mvc team under issue #8043.



        There is no problem with the ModelBinder. The problem was caused by my pager code, which constructs the url. Please use the link to view the full conversation which contains a detailed explanation from the aspnet/Mvc team and sample code provided by me.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 13 '18 at 13:58









        WinthorpeWinthorpe

        95215




        95215






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50365051%2fcontroller-action-with-multiple-parameters%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine