Reputation: 93
how i can display "Name - LastName" with ViewBag?
<h2> @{ViewBag.Name;} - @{ViewBag.LastName;} </h2>
I have error
Upvotes: 5
Views: 28877
Reputation: 1797
<h2> @ViewBag.Name - @ViewBag.LastName </h2>
avoid the extra { and you are good
Upvotes: 0
Reputation: 218732
<h2> @ViewBag.Name - @ViewBag.LastName </h2>
you only need @
.
I strongly suggest you to start using strongly typed views instead of using ViewBag. strongly typed views keeps your views ( and code ) clean and maintainable.
Upvotes: 2
Reputation: 8592
I don't know what you pass via the ViewBag, but do remove the brackets
<h2> @ViewBag.Name - @ViewBag.LastName </h2>
Upvotes: 10