Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.Display does not work with ViewBag

Html.Display does not work with ViewBag.

@Html.Display("disp", (string)@ViewBag.disp)

I must use this viewbag because it can be modified by a search button selecting another disp.

@Html.TextBox("disp", (string)@ViewBag.disp)

If I use TextBox instead of Display it works, but I want to be read-only. How it is possible?

like image 836
arnoldrob Avatar asked Oct 20 '25 04:10

arnoldrob


1 Answers

Because there's no overload of Display which takes a value as argument.

So.

You can simply do

@ViewBag.disp

or (if it contains HTMl)

@Html.Raw(ViewBag.disp)

or if you want a TextBox

@Html.TextBox("disp", (string)@ViewBag.disp, new{@readonly = true})
like image 98
Raphaël Althaus Avatar answered Oct 22 '25 05:10

Raphaël Althaus