我可以在剃刀视图中从数据库中检索数据吗? [英] Can I retrieve data from database in razor view?

查看:80
本文介绍了我可以在剃刀视图中从数据库中检索数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在剃刀视图中从数据库中检索数据吗?

如果是,如何写它。

Can I retrieve data from database in razor view?
If yes, how to write it.

推荐答案

无论视图是Razer还是aspx,你都可以随时从数据库中检索数据。 ..在控制器中写一个动作方法。在该操作方法中,编写逻辑以从数据库获取数据。利用ADO.NET概念。将数据分配给模型。将此模型返回到关联的Razer视图。 :)。如果您不知道编写代码或如何实现,请通过一些关于MVC的在线教程
Irrespective of whether view is Razer or aspx, u can always retrieve data from database... Write an action method in controller. In that action method, write the logic to get data from database. Make use of ADO.NET concept. Assign data to a model. Return this model to associated Razer view. :). If u do not know writing code or how to implement, kindly go through some online tutorials on MVC


是的,它可能但是它违反了关注点的分离。 View应该只关注创建发送到浏览器的HTML。



如果你需要将数据发送到View来创建HTML,那么Controller应该去获取它并将其放入视图模型中以发送到视图。
Yes, it's possible but it violates the separation of concerns. The View should be concerned only with the creation of the HTML to send to the browser.

If you need to send data to the View to create that HTML, the Controller should go get it and place it into the view model to be sent to the View.


这篇关于我可以在剃刀视图中从数据库中检索数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆