title: View page does not recognize null element in load
body: <p>I have an javascript function that generates links in my page based on a DropDown. I'm checking the javascript function in two places; when the DropDown changes with attribute "onchange", and when the page is loaded. The error is generated when the page is loaded without element on viewbag, my javascript is not recognizing the null element for generate links without the information on viewbag.</p>
  
  <pre><code>&lt;p&gt;Pesquisar por: @Html.DropDownList("tipoPesquisa", ViewBag.DropDownPesquisa as SelectList, new { onchange = "alteraFiltro()" }) 
  
  
  
  &lt;div id="dadosFornecedor"&gt;
          @if (ViewBag.CurrentFornecedor != null)
          {
              &lt;fieldset&gt;
                  &lt;legend&gt;@ViewBag.CurrentFornecedor.RazaoSocial&lt;/legend&gt;
                  &lt;b&gt;Razão Social:&lt;/b&gt; @ViewBag.CurrentFornecedor.RazaoSocial &lt;b&gt;Endereço:&lt;/b&gt; @ViewBag.CurrentFornecedor.Endereco
                  @Html.Hidden("idFornecedor", new { IdFornecedor = ViewBag.CurrentFornecedor.IdFornecedor })
                  &lt;input type="button" class="btn" onclick="removerFornecedor();" value="Remover Fornecedor" /&gt;
                  &lt;br /&gt;
                  &lt;br /&gt;
              &lt;/fieldset&gt;
              &lt;br /&gt;
  
          }
      &lt;/div&gt;
  
  
  &lt;script type="text/javascript"&gt;
      $(function () {
  
         alteraFiltro();
      });
  
      function removerFornecedor() {
          var div = $("#dadosFornecedor");
          var hidden = $("#idFornecedor");
          div.empty();
  
          div.append("&lt;input type='hidden' name='deletarFornecedor' value='true' /&gt;")
  
      }
  
          function alteraFiltro() {
              var urlCodigo = $("#linkCodigo");
              var urlLancamento = $("#linkLancamento");
              var urlPagamento = $("#linkPagamento");
              var urlFornecedor = $("#linkFornecedor")
              var dropValue = $("#tipoPesquisa").val();
              var hidden = $("#idFornecedor");
  
              if (hidden.val() == "" || hidden.val() == null || hidden == null) {
                  urlCodigo.attr("href", "saidasDiversas?sortOrder=@ViewBag.CodigoSortParm&amp;currentFilter=@ViewBag.CurrentFilter&amp;currentDrop=" + dropValue + "");
                  urlLancamento.attr("href", "saidasDiversas?sortOrder=@ViewBag.DataLancamentoSortParm&amp;currentFilter=@ViewBag.CurrentFilter&amp;currentDrop=" + dropValue + "");
                  urlPagamento.attr("href", "saidasDiversas?sortOrder=@ViewBag.DataPagamentoSortParm&amp;currentFilter=@ViewBag.CurrentFilter&amp;currentDrop=" + dropValue + "");
                  urlFornecedor.attr("href", "saidasDiversas?sortOrder=@ViewBag.FornecedorSortParm&amp;currentFilter=@ViewBag.CurrentFilter&amp;currentDrop=" + dropValue + "")
              } else{
                  urlCodigo.attr("href", "saidasDiversas?sortOrder=@ViewBag.CodigoSortParm&amp;idFornecedor=@ViewBag.CurrentFornecedor.IdFornecedor&amp;currentFilter=@ViewBag.CurrentFilter&amp;currentDrop=" + dropValue + "");
                  urlLancamento.attr("href", "saidasDiversas?sortOrder=@ViewBag.DataLancamentoSortParm&amp;idFornecedor=@ViewBag.CurrentFornecedor.IdFornecedor&amp;currentFilter=@ViewBag.CurrentFilter&amp;currentDrop=" + dropValue + "");
                  urlPagamento.attr("href", "saidasDiversas?sortOrder=@ViewBag.DataPagamentoSortParm&amp;idFornecedor=@ViewBag.CurrentFornecedor.IdFornecedor&amp;currentFilter=@ViewBag.CurrentFilter&amp;currentDrop=" + dropValue + "");
                  urlFornecedor.attr("href", "saidasDiversas?sortOrder=@ViewBag.FornecedorSortParm&amp;idFornecedor=@ViewBag.CurrentFornecedor.IdFornecedor&amp;currentFilter=@ViewBag.CurrentFilter&amp;currentDrop=" + dropValue + "")
              }
  
          }
  
  
      &lt;/script&gt;
  </code></pre>