0

I have a column line of code to display the data. For some reason, the "if" reads text, not a program

the following line code for kendo ui asp.net mvc

@{
  var queryLevel = ViewBag.queryLevel as string;
}


columns.Template(@<text></text>).ClientTemplate(
   "<div class=\"text-center\">" +

      "if ("+ queryLevel +" == \"Well\") {" +
         "<span>Ya</span>" +
      "}" +

      "<form action=\"/AssetOperationProduction/Update\" method=\"post\" style=\"display:inline\">" +
      "<input type=\"hidden\" name=\"Id\" value=\"#= Id #\" />" +
      "<button class=\"btn btn-secondary text-white m-1\" type=\"submit\"><i class=\"fa-solid fa-pencil\"></i></button></form>" +

      "<form action=\"/AssetOperationProduction/Delete\" method=\"post\" style=\"display:inline\">" +
      "<input type=\"hidden\" name=\"Id\" value=\"#= Id #\" />" +
      "<button class=\"btn btn-danger text-white m-1\" type=\"submit\"><i class=\"fa-solid fa-trash\"></i> "+ queryLevel +" </button></form>" +

      "</div>"
).Width(200);

1 Answer 1

2

You are essentially trying to access a ViewBag variable in JS. Check this thread for details on doing so. Also you should use the template syntax and wrap the if statement in # symbols so the JS code is evaluated as such, rather than as text:

@{
   var queryLevel = ViewBag.queryLevel as string;
}
<script>
   var myVariable = '@ViewBag.queryLevel';
</script>

You can then have:

.ClientTemplate(
"<div class=\"text-center\">" +
  "#if (myVariable == \"Well\") {#" +
     "<span>Ya</span>" +
  "#}#" +
 ...
 )

Here is an example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.