Giving Hide on an ActionLink, is it possible?

1

I would like depending on whether my ActionLink was visible or not.

Razor :

<td>
      @Html.ActionLink("Cadastrar site","MontarFancyCadastrarSite", "ItemOS", 
       new {ChaveOS = Model.ChaveOS }, new { @class = "siteFancybox fancybox.iframe" })
</td>

JQuery :

$("#ChaveSite").change(function () {
   $.getJSON('@Url.Action("CarregarContatoSite","OS")',{chaveSite: $('#ChaveSite').val()}, 
     function (contatos) {
        if (contatos.length > 0)
        {
            $(this).parent().find("a.siteFancybox fancybox.iframe").show();
        } else {                              
            $(this).parent().find("a.siteFancybox fancybox.iframe").hide();
        }
    })
});

That way it's not working, could someone show me the error or another way to do it?

    
asked by anonymous 03.01.2017 / 22:02

2 answers

0

I was able to solve this:

First, set the Id in the element on

RAZOR:

            <td>
                @Html.ActionLink("Cadastrar site","MontarFancyCadastrarSite", "ItemOS", 
                new {ChaveOS = Model.ChaveOS }, new { @class = "siteFancybox fancybox.iframe", id="cadastrarSite" })
            </td>

And JQuery:

  $("#ChaveSite").change(function () {
    $.getJSON('@Url.Action("CarregarContatoSite", "OS")', { chaveSite: $('#ChaveSite').val() }, function (contatos) {
        if (contatos.length > 0) {               
             $("#cadastrarSite").show();
        } else {                              
            $("#cadastrarSite").hide();
        }
    })
});

It worked perfectly for my problem.

    
04.01.2017 / 20:45
1

Instead of this:

$(this).parent().find("a.siteFancybox fancybox.iframe").show();

put this:

$('a.siteFancybox').parent().show();

I believe that he is not finding the correct item, even because in his question you did not specify where he was #ChaveSite

A simple example:

var contatos = 1;
$("#select").on("change", function()
{
  contatos = (contatos == 1) ? 0 : 1;
  if (contatos == 1) {
    $("a.siteFancybox").parent().show();
  } else {
    $("a.siteFancybox").parent().hide();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><selectid="select">
    <option value="1">Aparecer</option>
    <option value="0">Desaparecer</option>
  </select>
</div>
<table>
  <tr>
    <td>
      <a href="http://www.uol.com.br" 
         class="siteFancybox fancybox.iframe">Uol</a>
    </td>
  </tr>
</table>
    
04.01.2017 / 00:30