出于设计目的,asp.net mvc 在 ascx 文件中创建 ac# 类
我正在使用 ASP.NET MVC 开发一个 Web 应用程序。
我遇到需要暂时在 ascx/aspx 文件中创建一个类。
该类将在页面开发过程中替代Model。
它还将保存一些测试数据,以便用户有机会看到一些结果。
一旦我们对屏幕上的布局感到满意,我将通过 Control 标记继承正确的 Model 类。
您能否告知这是否可能以及如何做到?
这不起作用:
<%
class Modelo
{
public Guid Guid { get; set; }
public string Name { get; set; }
}
%>
编辑:
我发现,当我与用户坐在一起讨论屏幕上的控件的细节时,在许多情况下,当他/她看到结果并我们讨论它们时,他/她会要求更改某些内容。在控制器、模型和假数据存储库之间移动会消耗时间。即使用户非常聪明,他/她也无法跟上我正在做的事情,并且感觉参与度较低。如果每件事都集中在一个地方,我可以向他们解释我在做什么,他们至少会觉得他们知道发生了什么,我们会花更多的时间工作,而更少的时间等待我在屏幕之间切换。他/她离开后我可以安静地坐下来,安静地执行商定的解决方案。通过在实际控制上保留一个包含代表模型的假数据的类,我需要做的就是一些内务处理以满足 MVC 的做事方式。
希望现在更清楚了。
提前致谢,祝你快乐 - 朱利安
I am developing a web application using asp.net mvc.
I have come across the need to Temporarily create a class in the ascx/aspx file.
This class will replace the Model during the development of the page.
It will also hold some test data for the user to have the chance to see some results.
Once we are happy with the layout on the screen, I will inherit the correct Model class through the Control tag.
Can you please advise if this is possible and how to do it?
This does not work:
<%
class Modelo
{
public Guid Guid { get; set; }
public string Name { get; set; }
}
%>
Edit:
I have found that when I am sitting with the user and we are discussing the specifics of a control on the screen, in many cases when he/she sees the results and we discuss them he/she asks to change something. Moving between the controller, the model and the fake data repository consumes time. Even though the user is quit intelligent he/she can not follow what I am doing and feels less involved. If every thing was in one place I could explain to them what I am doing , they would at least feel that they know what is happening and we spend more time working and less time waiting for me to switch between screens. After he/she leaves I can sit down quietly and implement the agreed solution quietly. By keeping a class with fake data representing the model on the actual control all I will need to do is some housekeeping to meet the MVC way of doing things.
Hope it is more clear now.
Thanks in advance, Be happy - Julian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
满足您需求的替代方法可能如下:
您像平常一样将视图基于 ViewModel,但是将视图模型复制到用于显示目的的“DisplayModel”局部变量中。如果控制器未提供任何值,则可以在开发演示阶段本地设置其中的值。
An alternative approach that would meet your needs could be as follows:
You base your view on a ViewModel as you would normally, however you copy the view model into a 'DisplayModel' local variable that you use for display purposes. The values in this can be set locally during the development demo stage - if no values have been supplied by the controller.
为什么不直接对视图中的值进行硬编码?另一种可能性是使用真实的模型类,但在控制器内使用虚拟存储库,该存储库将用临时数据填充模型。一旦最终存储库准备就绪,您所要做的就是指示 DI 框架将真实存储库传递给控制器。
恕我直言,在视图中创建临时类不会带来太多价值,也不会赢得时间。
Why don't you directly hardcode the values in the view? Another possibility is to use the real model class but use a dummy repository inside the controller which will fill the model with temporary data. Once the final repository is ready all you have to do is instruct your DI framework to pass the real repository to the controller.
IMHO creating temporary classes inside the views wouldn't bring much value nor you will gain time.
好吧,你无法真正实现你想要的,因为视图处理器并不完全像隐藏的代码。
最好的选择是在控制器中创建一个临时类,然后将其传递给视图。至少需要一些步骤,而且在两个窗口之间切换应该不会花太长时间。
Well, you can't really achieve what you want, as the view processor is not exactly like a code behind.
Your best bet would be to create a temporary class in your controller, and then pass that to the view. At least it takes some steps out of the way, and it shouldn't take too long to switch between only two windows.