How to map a 1 or 0 in an ASP.Net MVC route segment into a Boolean action method input parameter

后端 未结 4 1593
无人共我
无人共我 2021-01-12 01:25

We have some PHP and Javascript apps that call into some ASP.NET MVC endpoints. Let\'s say we have this endpoint:

public ActionResult DoSomething(bool flag)
         


        
4条回答
  •  星月不相逢
    2021-01-12 02:22

    This is a workaround but it's sample in ultimate instance if you don't want modify or create a model binder.

    public ActionResult DoSomething(string flag)
    {
    
          if(flag.Equals("true") || flag.Equals(1)) {
                //condition true, any else false
          }
    
    
    }
    

提交回复
热议问题