title: How to add alert class in viewbag from controller
body: <p>Here i am trying to add bootstrap alert class to the exception shown in ViewBag.message from controller on clicking the create button. But adding the class shows the exception 'string' does not contain a definition for 'cssClass'.<br><br>
  Below Is Create.cshtml<br><br></p>
  
  <pre><code>    @model WebApplication8.Models.Info
  
     @{
        ViewBag.Title = "Create";
      }
     &lt;h2&gt;Create&lt;/h2&gt;
  
       &lt;div class="errormsg"&gt;  
           @ViewBag.message
      &lt;/div&gt;
  
      @using (Html.BeginForm()) 
      {
        @Html.AntiForgeryToken()
  
       &lt;div class="form-horizontal"&gt;
      &lt;h4&gt;Info&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true, "", new { @class = "text-danger" })
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.name, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.name, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.name, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.des, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.des, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.des, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  }
  
   &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
   &lt;/div&gt;
  
   @section Scripts {
     @Scripts.Render("~/bundles/jqueryval")
   }
  </code></pre>
  
  <p><br><br>
  Below is Create Action Method In controller<br><br></p>
  
  <pre><code>[HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = "id,name,des")] Info info)
      {
  
          try
          {
  
              if (ModelState.IsValid)
              {
  
                  db.create(info);                  
                  return RedirectToAction("Index");
              }
  
          }
          catch (Exception ex)
          {
  
              ViewBag.message =  ex.Message;
              ViewBag.message.cssClass = "alert alert-danger";
              return View(info);
          }
          return View(info);
  
      }
  </code></pre>
  
  <p><br><br>
  below is Interface Implementer class<br><br></p>
  
  <pre><code>public class StudentInfo : IStudentInfo
  {
      private AbcdEntities db1 = new AbcdEntities();
  
      public void create(Info info)
      {
          if (info.name!=null)
          {
              if (info.des!=null)
              {
                  db1.Infoes.Add(info);
                  db1.SaveChanges();
              }
              else
              {
  
                  throw new Exception("Des Cannot Be Empty");
              }
  
          }
          else
          {
              throw new Exception("Name Cannot Be Empty");
          }
      }
  </code></pre>