0

Using Asp.net Core

I'm dynamically creating a form and want to get the field names and its values from the controller side, so I'm using HttpContext.Request.Form.Keys which works fine for input text.

Basically I do a iteration and I get everything I want.

 foreach (string key in HttpContext.Request.Form.Keys)
        {
            string field = key;
            string s = HttpContext.Request.Form[key];
        }

But the problem is when I want to use Checkbox, those checkbox that are not "checked" will not come in HttpContext.Request.Form.Keys

All form fields will be stored in HttpContext.Request.Form.Keys except the checkbox that are not checked...

Any Idea why it happens or how I could fix it?

Ale Garcia
  • 180
  • 1
  • 2
  • 16

1 Answers1

0

This is by design. What you can do is check if the key exists and if it doesn't than it is not checked otherwise it is checked.

OR

You can check this answer for alternative approach.

Robert
  • 2,407
  • 1
  • 24
  • 35