简体   繁体   中英

ViewBag.Title not working in my code ASP.NET MVC 4

I am new to Visual Studio and am having difficulty making the ViewBag.Title function correctly.

Here is my code the ViewBag.Title is not working properly and gettin printed on screen in incorrect position and as the full string "ViewBag.Title = "Home Page";"

  @model IEnumerable<Employees.Models.Employee>
  @{WebGrid grid = new WebGrid(Model);}
  {
  ViewBag.Title = "Home Page";
  }
  @section featured {
       <section class="featured">
           <div class="content-wrapper">
               <hgroup class="title">
                  <h1>@ViewBag.Title.</h1>
                  <h2>@ViewBag.Message</h2>
               </hgroup>
   @grid.GetHtml(columns: new[] {
   ....
   ....

I'm pretty sure you just need to prefix that code block where you assign the ViewBag.Title with an @

@{
  ViewBag.Title = "Home Page";
  }

This was rendering as is like it was straight HTML

在SubViews(局部视图)TempData中使用标题

  TempData["pagetitle"] = "Title"; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM