ASP.NET MVC textbox

michael1174
michael1174 used Ask the Experts™
on
I have a text box that I need to read its value.  I verified I am correctly assigning the value to the textbox (last line of code). But, the if condition is not working.  Am I correctly coding this?  I will have to change this into a hidden field, but for now, I just need to get the if condition below working.

Thanks.

<% if (Html.TextBox("UnlimitedSlots").Equals("true"))
  { %>
    Slots: Unlimited <br />
<% } else  { %>
    Slots: <%= Html.TextBoxFor(x => x.Slots)%><br />
<% } %>
<br />

set textbox: <%= Html.TextBox("UnlimitedSlots") %>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hopefully I'm not missing something silly here.

You say you verified the contents in the last line. That line outputs the text "true"? I don't see how that could be. I'd expect it to output HTML.

Html.TextBox() is a rendering helper. It looks like you're trying to compare the return string of it (which is the HTML tags required to render the html input controls) against the literal string "true", which would never be the case.

This is sever-side rendering and the helpers render HTML. They don't QUERY contents of controls. You'd want to base your logic on the model's content, which is what you're rendering INSIDE the controls that the helpers create.
True was input into the html text box, but it was getting set after I needed it to.  I'm working with the telerik mvc controls. Using the grid when I add/edit a row, I needed to set it on the grid's event.  I can't use the model for new records because telerik has a current limitation when adding new records, its a dummy record and doesn't read from the model as far as I can tell and research.

I go around my issue by using the onedit event of the grid.

Thanks..

Author

Commented:
No comments were made that helped me answer my own question

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial