0

I have a partial view that I'm using for user input. I want to show the same partial view on a results page, but I want all of the input items to be readonly or disabled.

I know that I can use if-else syntax, but I really only want to set the readonly or disabled flag on the item, so duplicating the whole entity seems heavy handed and repetitive.

What I want is to be able to toggle between:

@Html.TextBoxFor(model => model.inputValue, new {disabled="disabled", @id="one"})

and

@Html.TextBoxFor(model => model.inputValue, new {@id="one"})

or readonly, if that's easier to manipulate.

Based on other answers, I gather that this is discouraged due to the separation of concerns, but I hate the idea of having to maintain two files when one will do.

So, the question is: what is the proper syntax to use to accomplish this.

1 Answer 1

2

Keep a Boolean ViewBag in the view, and set it when you render the view from the controller.

Check the value of this ViewBag when rendering these textboxes.

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

3 Comments

I know how to tell when to use which kind of entry, but I want to know what syntax I can use to do the job. I edited the question to make that clearer.
@wandercoder Have a look at this: stackoverflow.com/questions/9086104/…
Beautiful. The example cleared it up for me. Thanks.

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.