2

My LINQ query for retrieving data:

public ActionResult GetRegFirmList()
        {
            try
            {
                var data = (from z in db.BusinessModels
                            select z).OrderByDescending(z => z.BusinessKey).ToList();
                return View(data);
            }
            catch (Exception ex) { throw; }
        }

I have two action link buttons in the jQuery datatable. I need to hide the button for Certificate if the value of Status is 1 in the particular row. The action link button for Application should not be hidden. How can I do that?

<link href="~/Content/DataTables/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<table id="tblBusinessData">
    <thead class="table-success">
        <tr>
            <th>generate</th>
            <th style="visibility:hidden;">
                @Html.DisplayNameFor(model => model.BusinessKey)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.BusinessName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.PropName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Status)
            </th>
            
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.ActionLink("Certificate", "GenerateCertificate", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })
                    @Html.ActionLink("Application", "GenerateApplication", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })
                </td>
                <td style="visibility:hidden;">
                    @Html.DisplayFor(modelItem => item.BusinessKey)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.BusinessName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PropName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Status)
                </td>
            </tr>
        }
    </tbody>
</table>
<script src="~/Scripts/DataTables/jquery.dataTables.min.js"></script>
<script src="~/Scripts/DataTables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript">
    $('#tblBusinessData').DataTable({
        "columnDefs": [{
            "targets": [1],
            "visible": false
        }],
        "order": [
            [1, "desc"]
        ]
    });
</script>

1 Answer 1

2

You can add condition like this

@if(item.Status!=1)  
{
    @Html.ActionLink("Certificate", "GenerateCertificate", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })
}

So your foreach loop should be like below

@foreach (var item in Model)
{
    <tr>
        <td>
            @(item.Status!=1){@Html.ActionLink("Certificate", "GenerateCertificate", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })}
            @Html.ActionLink("Application", "GenerateApplication", new { id = item.BusinessKey }, new { @class = "btn btn-warning" })
        </td>
        <td style="visibility:hidden;">
            @Html.DisplayFor(modelItem => item.BusinessKey)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.BusinessName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PropName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Status)
        </td>
    </tr>
}
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.