MvcHtmlString.Create () returns a semicolon ";"

1

I'm new to this with ASP .Net MVC, I have the following Helper that should show me an icon indicating the sort order (Ascending or descending):

public static IHtmlString IndicaOrden(this HtmlHelper htmlHelper, string sortOrden, string campo)
    {
        if (string.IsNullOrEmpty(sortOrden) || (sortOrden.Trim() != campo && sortOrden.Replace("_desc", "").Trim() != campo))
            return null;

        string icono = "glyphicon glyphicon-chevron-up";
        if (sortOrden.ToLower().Contains("desc"))
        {
            icono = "glyphicon glyphicon-chevron-down";
        }

        var tag = new TagBuilder("span");
        tag.Attributes["class"] = icono;

        return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
    }

Instead of returning an HTML tag " <span class="glypicon glyphicon-chevron-up"></span> " returns me ";"

Here I make the call in the view:

<th>
            @Html.ActionLink("Ficha","Index",Request.QueryString.ParametrosURL("sortOrden", (string)ViewBag.FichaSort ) )
            @Html.IndicaOrden(sortActual,"VEH_FICHA");
</th>

I really can not find the problem.

Greetings.

    
asked by Enecumene 06.03.2018 в 18:15
source

1 answer

1

We go in parts:

Returns that ";" because you already have it on the side of the last parenthesis.

The following block of code is fulfilled:

if (string.IsNullOrEmpty(sortOrden) || 
   (sortOrden.Trim() != campo && sortOrden.Replace("_desc", "").Trim() != campo))
            return null;

returning a null

    
answered by 06.03.2018 / 18:27
source