0

I am using MVC Mailer - but for some reason when the view is rendered there is nothing in ViewBag. My code looks like this

  ViewBag.test = "This should appear in the view";

            MvcMailMessage m = new MvcMailMessage();               
            MailerBase mb = new MailerBase();
            m = mb.Populate(x =>
            {
                x.Subject = "Welcome";
                x.ViewName = "../Mails/Email_ForgotPassword";
                x.To.Add("g@gmail.com");
            });

            m.Send();
            ModelState.AddModelError("", "Success! Password sent");

I can only imagine that it is some weird setting or something I have omitted - because ViewBag.test in the view is NULL.

Any help much appreciated!

Satpal
  • 132,252
  • 13
  • 159
  • 168
Gavin
  • 21
  • 3
  • Where are you calling the MVC mailer code and where are you trying to set and use ViebBag.test? – Amit Rai Sharma Apr 16 '13 at 12:53
  • This code is in the context of a standard controller. Viewbag.test is being set as shown above, and i am trying to use it in the view called Email_forgotPassword. – Gavin Apr 16 '13 at 20:31
  • I have resorted to replacing Viewbag.test to Session["test"].. this can then be picked up in the view. Its ugly but there seems to be no other option :-( – Gavin Apr 20 '13 at 08:48
  • ViewBag.test should be available in the view. Can you paste the controller and view code. It will give a better idea on what's going on. – Amit Rai Sharma Apr 20 '13 at 15:07

1 Answers1

0

I am getting similar issue after installing Update 2 on Visual Studio 2012. I haven't found a fix for it. However if you run VS 2012 in Administrator mode you won't get this problem.

Amit Rai Sharma
  • 4,015
  • 1
  • 28
  • 35