Click here to Skip to main content
15,888,263 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public PartialViewResult Sub1(SuperVM picvm)
        {
            picvm = new SuperVM()
            {
                SubsCribe = new SubsCribe()
                {
                    SubscribeEmail = picvm.SubsCribe.SubscribeEmail,
                     Subject =picvm.SubsCribe.Subject
                }
            };
            SmtpClient smtp = new SmtpClient("mail.ABC.com");
            if(ModelState.IsValid)
            {
                MailMessage mail = new MailMessage();
                mail.To.Add(new MailAddress("ABC@gmail.com"));
                mail.Bcc.Add(new MailAddress(picvm.SubsCribe.SubscribeEmail));
                mail.From = new MailAddress("admin@ABC.com");
                mail.Subject = picvm.SubsCribe.SubscribeEmail + " ****-----Subscribed------****** ";
                mail.Body = string.Format(mail.Subject);
                mail.IsBodyHtml = true;
              
                smtp.Port = 25;
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = new System.Net.NetworkCredential("admin@ABC.com", 1234567 ");
                smtp.EnableSsl = false;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.Send(mail);

                db.SubsCribes.Add(picvm.SubsCribe);
                db.SaveChanges();
                return PartialView("Sub1",picvm);
            }

            else
            {
                return PartialView();
            }
        }


What I have tried:

I am trying to Send Email - which is working,
But along I am trying to save email Id(Model property -
SubscribeEmail 
) to database.

So along with above mailing stuff I am adding this lines :
db.SubsCribes.Add(picvm.SubsCribe);
                db.SaveChanges();



Email is sending successfully, but, email id is not saving to database.

Please Help.
Thanks in Advance.
Posted
Updated 30-Dec-16 21:10pm
Comments
Any exception?
Aman.Jen 30-Dec-16 20:56pm    
No exception My Friend
Interesting!!! Table exists in db?

1 solution

As far as i understand your code you are initializing two models SuperVM as picvm and SubsCribe as SubsCribe in your partialview result. You are not setting any value to the picvm.SubsCribe.SubscribeEmail. So instead of initializing model in you partialview result method send model data to the partialview method or set the value in partialview like

C#
picvm.SubsCribe.SubscribeEmail = abc@some.com


but if you are sending data to the partialview method then please explain why are you using below code?

picvm = new SuperVM()
{
SubsCribe = new SubsCribe()
{
SubscribeEmail = picvm.SubsCribe.SubscribeEmail,
Subject =picvm.SubsCribe.Subject
}
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900