smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
584 stars 178 forks source link

Allow Views with Models #19

Closed Korayem closed 13 years ago

Korayem commented 13 years ago

You may not consider this an "issue" but seeing how MvcMailer is all about MVC, i think not having a model in the view is an "issue". Relying on Viewbag is cool, but why not really follow the MVC pattern?

Would love to have my razor views setup a model type so that I can pass the model into the view using PopulateBody();

This should be possible: var model = new ModelView(); model.FirstName = "Hello"; model.LastName = "World"; PopulateBody(mailMessage, "RazorView", model);

so that in RazorView.cshtml @model MyModelView This is a @Model.FirstName @Model.LastName app!

smsohan commented 13 years ago

Just assign your model to this.ViewData and your view will find it as any other view data passed into it.


Sent from my iPhone

S M Sohan Consultant ThoughtWorks Canada Suite 1100, 600 6th Ave SW Calgary, AB T2P 0S5 Cell: +1 403 714 2673

On 2011-06-24, at 5:21 PM, Korayem reply@reply.github.com wrote:

You may not consider this an "issue" but seeing how MvcMailer is all about MVC, i think not having a model in the view is an "issue". Relying on Viewbag is cool, but why not really follow the MVC pattern?

Would love to have my razor views setup a model type so that I can pass the model into the view using PopulateBody();

This should be possible: var model = new ModelView(); model.FirstName = "Hello"; model.LastName = "World"; PopulateBody(mailMessage, "RazorView", model);

so that in RazorView.cshtml @model MyModelView This is a @Model.FirstName @Model.LastName app!

Reply to this email directly or view it on GitHub: https://github.com/smsohan/MvcMailer/issues/19

Korayem commented 13 years ago

Doh!!!

So it should be as simple as var model = new ModelView(); ViewData = new ViewDataDictionary(model);

Never knew that. Thought I had to pass it as a parameter! I suggest you add this small tip to your wiki post for the ignorant folks like me :)

Sorry for the trouble and a million thanks for the quick response

smsohan commented 13 years ago

:)


Sent from my iPhone

S M Sohan Consultant ThoughtWorks Canada Suite 1100, 600 6th Ave SW Calgary, AB T2P 0S5 Cell: +1 403 714 2673

On 2011-06-24, at 11:11 PM, Korayem reply@reply.github.com wrote:

Doh!!!

So it should be as simple as var model = new ModelView(); ViewData = new ViewDataDictionary(model);

Never knew that. Thought I had to pass it as a parameter! I suggest you add this small tip to your wiki post for the ignorant folks like me :)

Sorry for the trouble and a million thanks for the quick reponse

Reply to this email directly or view it on GitHub: https://github.com/smsohan/MvcMailer/issues/19#issuecomment-1437020

junxy commented 10 years ago

;) :+1: