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.

wandercoder
  • 392
  • 2
  • 16

1 Answers1

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.

Bhushan Shah
  • 1,028
  • 8
  • 20