Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Views with Models #19

Closed
Korayem opened this issue Jun 24, 2011 · 4 comments
Closed

Allow Views with Models #19

Korayem opened this issue Jun 24, 2011 · 4 comments

Comments

@Korayem
Copy link

Korayem commented Jun 24, 2011

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
Copy link
Owner

smsohan commented Jun 25, 2011

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:
#19

@Korayem
Copy link
Author

Korayem commented Jun 25, 2011

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

@Korayem Korayem closed this as completed Jun 25, 2011
@smsohan
Copy link
Owner

smsohan commented Jun 25, 2011

:)


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:
#19 (comment)

@junxy
Copy link

junxy commented Sep 26, 2013

;) 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants