Question

I am from C/C++ background and this simple problem is nightmare for me.

ViewBag.description = "description";

this viewbag contains stirng "descriptuon"

Here is editbox txtdescription and i want to assign this viewbag data to this textbox. (it would be awesome if i know that viewbag is contain any data or not)

<div>
       @Html.TextBox("txtDescription")
</div>

trust html asp is much more challanging than low level programming.

Was it helpful?

Solution

I am sorry to hear that you find web programming little not interesting. You can do following to bind your viewbag data in your textbox

@Html.TextBox("txtDescription", (string)ViewBag.Title)

As to check if ViewBag is null or not you can do following:

@if (ViewBag.Title != null)
{
    //do your textbox assignment here.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top