[RESOLVED]How to use html action link with if condition in mvc

Im using Telerik Grid.

I have 2 columns "status" and "View Details"

In column bound of "View Details" I have to check the "status" column value.

if it is success then I have to give link to the "View Details" column.

on click of view details im calling javascript and it continues.

I have written code like below.

columns.Bound(o => o.Status).Width(150).Title("Status").HeaderHtmlAttributes(new { style = "text-align:center" });

columns.Bound(o => o.ViewDetails).Width(50).Title("View Details").ClientTemplate("#

if (Status == ‘success’)
{ #" + @Html.ActionLink("View Details", "", "", new { onclick = "return onLinkClickViewDetails(‘<#= Calc_Job_Id #>’);" },

new { @Title = "see" }).ToHtmlString() + "# }
else {#"View Details"#} #").HtmlAttributes(new { @style = "text-align:center" });

If the "status" column’s data is Success then I have to show ViewDetail as a link
otherwise I have to show it as a text.

I cant figure out what is wrong in this code.Please help me.

I made some minor fixes. Try this

columns.Bound(o => o.ViewDetails).Width(50).Title("View Details").ClientTemplate(@"# 
 if (Status == 'success') 
 { #" + Html.ActionLink("View Details", "", "", new { onclick = "return onLinkClickViewDetails('<#= Calc_Job_Id #>');", @Title = "see" }).ToHtmlString() + 
 "# } else {#<div>View Details</div>#} #").HtmlAttributes(new { @style = "text-align:center" });

Hi Smitha,

if (Status == 'success') 
{
    //@Html.ActionLink("Detail","DetailAction","Controller")
@Html.ActionLink("View Details", "", "", new { onclick = "return onLinkClickViewDetails('<#= Calc_Job_Id #>');" } } else {
//@Html.Label("Detail") Detail }

Is this what you want??

Hope This Helps

Leave a Reply