Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ViewBag Message not displaying in view in mvc5

"New Movie" is not displaying in View. Instead, it is displaying "ViewBag.Message" directly. But the data in ViewModel works fine.

NewMovie Action Method:

public ViewResult NewMovie()
{
  var movieType = _context.MovieTypes.ToList();
  var viewModel = new MovieViewModel { MovieTypes = movieType };
  ViewBag.Message = "New Movie";
  return View("MovieForm", viewModel);
}

MovieForm View:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@model VideoRentalApp.ViewModel.MovieViewModel
@{
  ViewBag.Title = "Movie Information";
  Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>ViewBag.Message</h2>

>Solution :

Use <h2>@ViewBag.Message</h2>. The asterisk @ denotes a variable reference. Otherwise the razor compiler interprets the string as just that, a string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading