locked
Razer show/hide table columns RRS feed

  • Question

  • User-1104215994 posted

    Hi,

    I would like to show/hide RequestDateTime according to <g class="gr_ gr_52 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="52" data-gr-id="52">null</g> value. I tried to add if but I got model does not exist. How can I accomplish it?

    @if(model.RequestDateTime!=null
    @model IEnumerable<GameMonitor.Models.GameBanks>
    
    
    @{
        ViewData["Title"] = "Index";
    }
    
    <h2>Games</h2>
    
    <table class="table">
        <thead>
            <tr>
                
                <th>
                    @Html.DisplayNameFor(model => model.ProductCode)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Quantity)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.RequestDateTime)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Used)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ProductDescription)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.UnitPrice)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Status)
                </th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        @foreach (var item in Model)
        {
            <tr>
    
                <td>
                    @Html.DisplayFor(modelItem => item.ProductCode)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Quantity)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.RequestDateTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Used)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ProductDescription)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.UnitPrice)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Status)
                </td>
                <td>
                    <a asp-action="Details" asp-route-id="@item.GameBankId">Details</a>
    
                </td>
            </tr>
        }
        </tbody>
    </table>
    

    Monday, August 26, 2019 2:39 PM

Answers

  • User475983607 posted

    You defined the model as IEnumerable which is usually a result set. 

    Are you trying to check if the RequestDateTime field has a null value in the result set?

    @if(Model.Any(m => m.RequestDatetime == null))
    {
      //Has NULLs
    }
    else
    {
      //No NULLs found
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 26, 2019 2:53 PM