I'm coming from an ASP.NET background and have started with ASP.NET MVC so not sure if I'm doing something wrong here or missing some fundamental understanding.
I have a PartialView as shown below:
@{
Layout = "master.cshtml";
ContactForm form= new ContactForm();
form.Message = "Thank you, we shall be in touch";
}
I have my model with the Message property but is not being set in my controller only in the PV above. The purpose is the Message could be different for different forms.
I have a method which sends an email (this is fine and works, send all the fields from the form) but I would like the Message to be the one set in form.Message to be sent along when the form is submitted.
I read up on ViewBag but I think that's a temp value from the controller to the PV.
The code runs and sets the value for the Message on initial load which I established whilst debugging.
Once the method to send the email is reached (after clicking a button) all other fields are loaded except the Message value set on the PV.
How could I pass the Message from the partial view to my controller?