Question: I have a view which calls a view component and passes a model called Konstant in the following way:

```
@foreach (Konstant item in Model)
{
    <div class="tab-content">
        <div id="@item.KANAL" class="tab-pane fade in">
            @await Component.InvokeAsync("MeterReader2", new { k = item })
        </div>
    </div>
}

```

If we look at the ViewComponent, it looks like this:

```
public class MeterReader2ViewComponent : ViewComponent
{
    public async Task<IViewComponentResult> InvokeAsync(Models.Konstant k) 
    // Endast en kanal.
    { 
     // logic.... 
    }
}

```

So far, this works for me. My question however is, how do I introduce two textboxes in the view which should include start and end date fields, where the inputed values should be sent to the view component?

I was thinking something like:

```
<input type="text" id="startDate", name="start" value="" />
<input type="text" id="endDate", name="end" value="" />

```

And then:

```
@foreach (Konstant item in Model)
{
    <div class="tab-content">
        <div id="@item.KANAL" class="tab-pane fade in">
            @await Component.InvokeAsync("MeterReader2", new { k = item, start = startDate, end = endDate })
        </div>
    </div>
}

```

Lastly, within the View Component itself: include the parameters: 

```
public async Task<IViewComponentResult> InvokeAsync(Models.Konstant k, string start, string end) // Endast en kanal.
{ 
  // logic.... 
}

```

Any ideas?

Answer: 
Use [`coalesce()`](https://www.postgresql.org/docs/current/static/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL):

```
UPDATE accounts 
SET notifications =  jsonb_set(coalesce(notifications, '{}'), '{"alerts"}', 'false')

```

or even simpler:

```
UPDATE accounts 
SET notifications =  coalesce(notifications, '{}') || '{"alerts": false}'

```
Note that some versions of Postgres have coalesce() functions that don't support jsonb, and will give an error like this when trying to use the accepted answer:

```
ERROR:  function coalsece(jsonb, unknown) does not exist

```

You can work around that by using a case statement instead. Ugly, but it works.

```
UPDATE accounts 
SET notifications = 
  jsonb_set(
    case
      when notifications is null then '{}'
      else notifications
    end,
    '{"alerts"}','false')

```