Conditional on a field in the view

1

I'm doing maintenance on MVC for an employees table. I have made a grid that shows the list of employees, and I added buttons to edit and delete in each record, but I want to say delete instead say "Give High" or "Unsubscribe" depending on the field state of the table employees . This is the code of the view:

@model IEnumerable<AppProfileDAL.v_employee>
@using GridMvc.Html

@{
   ViewBag.Title = "Index";
}
<div class="right-side">

<h2>Index</h2>

<p>
    @*@Html.ActionLink("Create New", "Create")*@
    <a href="@Url.Action("Create", "v_employee")" class="btn btn-primary active">
        <span class="glyphicon glyphicon-plus"></span> Nuevo
    </a>
</p>



@Html.Grid(Model).Columns(
columns =>
{
    columns.Add(c => c.nombres).Titled("Name");
    columns.Add(c => c.apellidos).Titled("Last Name");
    columns.Add().Sanitized(false).Encoded(false).RenderValueAs(o => Html.ActionLink("Editar", "Edit", "v_employee", new { Id = o.user_id}, null).ToHtmlString());
    if () { //Aquí esta el problema
        columns.Add().Sanitized(false).Encoded(false).RenderValueAs(o => Html.ActionLink("Down", "Delete", "v_employee", new { Id = o.user_id}, null).ToHtmlString());
    }
    else
    {
        columns.Add().Sanitized(false).Encoded(false).RenderValueAs(o => Html.ActionLink("Up", "Delete", "v_employee", new { Id = o.user_id}, null).ToHtmlString());
    }

    columns.Add().Sanitized(false).Encoded(false).RenderValueAs(o => Html.ActionLink("Imprimir", "Print", "v_employee", new { Id = o.user_id}, null).ToHtmlString());

}).WithPaging(10).Sortable(true)

Do you know any way to read the state field of the table and put it in the conditional of the if?

Thank you!

    
asked by FRANCISCO JOSE HERRERA MONCHEZ 08.03.2016 в 21:04
source

1 answer

1

The columns can not be conditional, or the samples or not, but it applies to the entire table. What you can vary is the content of the cells in each row for that column.

I would recommend that you define a single column and the conditional of the action you define it in format

columns.Add("Titulo Columna", format: (item) =>
        {
            if (condicion)
            {
                return Html.Raw(Html.ActionLink("Up", "Delete", "v_employee", new { Id = item.user_id}, null).ToHtmlString());
            }
            else
            {
                return Html.Raw(Html.ActionLink("Down", "Delete", "v_employee", new { Id = item.user_id}, null).ToHtmlString());
            }
        })

This way you show a link or another but under the same column.

    
answered by 08.03.2016 в 22:38