Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
92 views
in Technique[技术] by (71.8m points)

c# - MVC and ViewModels

I want to use the ViewModel-Pattern in connection with my MVC setup. I believe to have understood the idea, but I don't know how to behave in the following situtation:

My Model manages data, which I display in my view, but I also want to send the data via mail and add to Jira etc. In other words I also want to provide the data to an external program.

Before I had a ViewModel, I have set and gotten my data in the Controller, where I also have sent it via mail (and jira). I believe the sending part does not belong in the ViewModel, therefore now I had to construct complicated methods in the ViewModel to provide the data for the mail.

Does anybode know the correct behaviour here? Also I would be happy if somebody has a good resource about this topic.

Thank you!

Edit: I have a functionality like this:

sendMail(data1, data2, data3);
createJiraComment(data4, data5, dat6);

data1 to data6 hereby refer to data of my underlying database, which I "contact" via my ViewModel.

question from:https://stackoverflow.com/questions/65937545/mvc-and-viewmodels

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If I understands your problem correctly, you need some function that will allow to send the data to mail or any external source and you don't want to do it inside you view. The very basic solution is to write a middleware that will execute just after or just before the response you view is sending and you can code your logic for that inside the middleware. If you don't want to do it for every view you can create a class with same functionality and inherit it inside your view. Hope it clears.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...