ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Show Hide Hyperlink based on condition in ASP.Net MVC<p>Hi&nbsp;<a class="username" rel="mahesh213">mahesh213,</a></p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { // GET: /Home/ public ActionResult Index() { return View(); } public JsonResult getAll() { List&lt;Data&gt; data = new List&lt;Data&gt;(); data.Add(new Data { EId = 1, Id = 1, ControllerName = &#34;report&#34;, Url = &#34;/report/Index/&#34;, View = 1, Add = 0 }); data.Add(new Data { EId = 2, Id = 2, ControllerName = &#34;report1&#34;, Url = &#34;/eport1/Index/&#34;, View = 0, Add = 0 }); return Json(data, JsonRequestBehavior.AllowGet); } } public class Data { public int EId { get; set; } public int Id { get; set; } public string ControllerName { get; set; } public string Url { get; set; } public int View { get; set; } public int Add { get; set; } }</pre> <p><strong><span style="text-decoration: underline;">View</span></strong></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $.ajax({ type: &#34;POST&#34;, url: &#34;/Home/getAll/&#34;, contentType: &#34;application/json; charset=utf-8&#34;, data: {}, dataType: &#34;json&#34;, success: function (r) { var table = &#34;&lt;table&gt;&lt;tr&gt;&lt;th&gt;EId&lt;/th&gt;&lt;th&gt;Id&lt;/th&gt;&lt;th&gt;Controller Name&lt;/th&gt;&lt;th&gt;Url&lt;/th&gt;&lt;th&gt;View&lt;/th&gt;&lt;th&gt;Add&lt;/th&gt;&lt;/tr&gt;&#34;; $.each(r, function (i, item) { table += &#34;&lt;tr&gt;&lt;td&gt;&#34; + item.EId + &#34;&lt;/td&gt;&lt;td&gt;&#34; + item.Id + &#34;&lt;/td&gt;&lt;td&gt;&#34; + item.ControllerName + &#34;&lt;/td&gt;&lt;td&gt;&#34; + &#34;&lt;a href=&#39;&#34; + item.Url + &#34;&#39;&gt;&#34; + item.ControllerName + &#34;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&#34; + &#34;&lt;input type=&#39;checkbox&#39; onclick=&#39;SetValue(this)&#39; /&gt;&lt;input type=&#39;hidden&#39; value=&#39;&#34; + item.View + &#34;&#39; /&gt;&lt;/td&gt;&lt;td&gt;&#34; + &#34;&lt;input type=&#39;checkbox&#39; onclick=&#39;SetValue(this)&#39; /&gt;&lt;input type=&#39;hidden&#39; value=&#39;&#34; + item.Add + &#34;&#39; /&gt;&lt;/td&gt;&lt;/tr&gt;&#34;; }); table += &#34;&lt;/table&gt;&#34;; $(&#39;#dvData&#39;).html(table); ShowHide(); } }); }); function SetValue(ele) { $(ele).closest(&#39;td&#39;).find(&#39;input[type=hidden]&#39;).val($(ele).attr(&#39;checked&#39;) ? 1 : 0); ShowHide(); } function ShowHide() { $.each($(&#39;#dvData&#39;).find(&#39;table tr:has(td)&#39;), function (i, item) { var view = $(item).find(&#39;td&#39;).eq(4).find(&#39;input[type=hidden]&#39;).val(); var add = $(item).find(&#39;td&#39;).eq(5).find(&#39;input[type=hidden]&#39;).val(); if (view == 1) { $(item).find(&#39;td&#39;).eq(4).find(&#39;input[type=checkbox]&#39;).attr(&#39;checked&#39;, &#39;checked&#39;); } else { $(item).find(&#39;td&#39;).eq(4).find(&#39;input[type=checkbox]&#39;).removeAttr(&#39;checked&#39;); } if (add == 1) { $(item).find(&#39;td&#39;).eq(5).find(&#39;input[type=checkbox]&#39;).attr(&#39;checked&#39;, &#39;checked&#39;); } else { $(item).find(&#39;td&#39;).eq(5).find(&#39;input[type=checkbox]&#39;).removeAttr(&#39;checked&#39;); } if (view == 0 &amp;&amp; add == 0) { $(item).find(&#39;td&#39;).eq(3).find(&#39;a&#39;).hide(); } else { $(item).find(&#39;td&#39;).eq(3).find(&#39;a&#39;).show(); } }); } &lt;/script&gt; &lt;div id=&#34;dvData&#34;&gt; &lt;/div&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/JEXto1r.gif" alt="" width="326" height="178" /></span></strong></p>https://www.aspforums.net:443/Threads/170557/Show-Hide-Hyperlink-based-on-condition-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/170557/Show-Hide-Hyperlink-based-on-condition-in-ASPNet-MVC/Wed, 17 Jul 2019 07:16:04 GMT