使用ASP.NET MVC与通用视图 [英] Using ASP.NET MVC with generic views

查看:152
本文介绍了使用ASP.NET MVC与通用视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在调查的MVC,我们正在开始一个新的项目。到目前为止,我喜欢它,但我不知道的东西。

I am currently investigating MVC for a new project we are starting. So far I like it, but I'm wondering about something.

这是我们将展示不会在设计时是已知的实际意见,我们将在配置文件中指定的地方如何建立这些观点。这是由模式或MVC支持这样做,我们需要知道在设计时什么样的数据,我们将观看?

The actual views that we will be displaying will not be known at design time, we will be specifying in a config file somewhere how to build these views. Is this pattern supported by MVC or do we need to know at design time exactly what data we will be viewing?

如果不是,有人可以给我一些指点什么我应该看,因为大多数的信息,我有假定您有您的设计过程中定义的模型/视图。

If not, can someone give me some pointers on what I should be looking at as most of the info I have assumes that you have a model/view that is defined during your design.

问候,

亚历克斯..

推荐答案

您可以有你的看法弱类型的... ...查看您最初的页面指令看起来像:

You can have your views weakly-typed... Your initial page directive on the view will look like:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

...然后你可以参考的数据从你的控制器是这样的:

... and then you can refer to data from your Controllers like this:

<%= ViewData["MyData"] %>

是否有您打算传递给你的视图一些常用的接口?如果是这样,你可以受益于一个使用通用的ViewPage&LT;>:

Is there some common interface that you are intending to pass to your view? If so, you can benefit from a using the generic ViewPage<> :

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IamTheInterface>" %>

然后,您可以使用您的接口来引用您的型号:

Then, you can use your interface to refer to your Model:

<%= Model.MyProperty %>

这篇关于使用ASP.NET MVC与通用视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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