Click here to Skip to main content
15,891,649 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i bind the data for html.textbox based on some condition in view like below.
If long_variable is 0, i want to assign empty to the Html.TextBox, else the value which is in long_variable.

<%= Html.TextBox("long_variable", "", new { @class = "short"})%>


What I have tried:

i tried like below, but i don't know the exact thing to do.

<%if(Model.BagRunTime==0) { %>
<%= Html.TextBox("BagRunTime", "", new { @class = "short"})%>
Posted
Updated 11-Aug-16 2:55am

1 solution

Try using the ternary operator[^]:
ASP.NET
<%= Html.TextBox("long_variable", long_variable == 0 ? "" : long_variable.ToString(), new { @class = "short"}) %>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900