In the controller, the action puts the dynamic readOnly property in the ViewBag

public ActionResult Search() { ViewBag.readOnly = false; return View("Search"); } 

In the very view of the code:

 <%if (!ViewBag.readOnly) {%> <div id="CenterButtonsBlock"> <input type="button" class="k-button" id="AddSelectedDonors" value="Добавить в реестр почетных доноров"/> </div> <%}%> 

Those. it is assumed that the value is false, then the button should be shown. If true, the button should not be. In fact, the button is always visible.

  • Sloppy, what prevents to transfer model in View? - cpp_user
  • The project is not mine, I just finish it. I'm afraid to touch and everything will fall down - Dmitry
  • <% var _readOnly = string.IsNullOrEmpty (ViewBag.readOnly)? false: (bool) ViewBag.readOnly; if (! _readOnly) {... - Konst
  • @Dmitry: Well, see for yourself, errors in Runtime are always worse than when compiling and can cause significant problems. - cpp_user

2 answers 2

It seems so use it:

 @ViewBag.readOnly 
  • This is if the Razor engine). Konst thanks, helped! - Dmitriy
 <% var _readOnly = string.IsNullOrEmpty(ViewBag.readOnly) ? false:(bool)ViewBag.readOnly; if (!_readOnly) { ...