Hide in an Actionlink, is it possible?

Asked

Viewed 26 times

1

I’d like to depending on my condition 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 above is not working, someone could show me the error or other way to do it?

2 answers

1

Instead:

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

put this:

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

I believe he is not finding the correct item even because in your question you did not specify where you were #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>
  <select id="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>

  • #Chavesite is a DDL.

0


I managed to sort it out like this:

First, I put the ID in the

RAZOR:

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

And in the 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.