English 中文(简体)
ASP. NET MVC2 - 确定哪些类型的模板正在提供
原标题:ASP.NET MVC2 - Determine which type of template is being rendered

我不想使用显示器和编辑,而是想制作一个更通用的内容。 在这种Html的延伸中,它将考虑到元数据值,以确定如何实现由此产生的控制。 我确定的唯一难题是: 是否有办法确定我是否正在提供显示器模版或编辑模板。 作为这方面的一个现实世界例子,在提供插图时,我想把它作为显示版本,但在编辑版上,我想把它作为文字箱。

为了更好地解释,我要说,我有两个模板,即地址:ascx,一个是显示Templates名录,另一个是编辑版目录。 我希望两人都使用内容提要,但在显示版本中,内容是贴上标签,在编辑版本中,它成为文本箱。

问题回答

利用2个ASCX文档来进行单一档案控制(这是可以做到的,而另一个是投标或显示For/LabelFor)。 对我来说,这并不有意义。 它打破了“关切的消失”。 标签显示标签和显示价值,对尝试和显示你想要显示的那种控制是没有意义的。

如果你想要使用一种习俗,显示或贴上财产标签,则使用UIHint数据说明。

[UIHint("MyCustomControlName")]

然后,在显示器和编辑部中,制作了“MyCustomControlName.ascx”的档案,显示你想要的这种财产。 此外,轴心控制可以读到习惯模型元数据,并尽其所能。 http://weblogs.asp.net/seanmcalinden/archive/06/11/custom-asp-net-mvc-2-modelmetadataprovider-for-custom-view-model-attributes.aspx”rel=“nofollow noreferer”> http://weblogs.asp.net/seanmcalinden/archive/06/11/tom-net-mvc-2-modelmetadataprovider-for-for-cus-tom-delmo-view-view-atbuta.aspx。





相关问题
ASP.Net MVC - Handle Multiple Checkboxes

Ok, I have a role based permission system in place and would like admin s to be able to edit the permissions for each role. To do this I need to load lots of checkboxes, however I m struggling with ...

Entity Framework error when submitting empty fields

VS 2010 Beta 2, .NET 4. In my ASP.NET MVC 2 application, when I submit a form to an action method that accepts an object created by the entity framework, I get the following error: Exception Details:...

ASP.Net MVC Architecture - Location of ViewModels

We have a decent sized MVC project running well at the moment, i ve started to look at some re-factoring and I have a question. At the moment the Data Layer and Service Layer is stored in a seperate ...

ASP.Net MVC Go To Declaration On view

Is there anyway when in an MVC view to right click a function call and get to the declaration? Like you can do in the code behind/controllers

ASP.NET MVC 2 Beta - Default Model Binder

I m experiencing some different behavior after switching from ASP.NET MVC 1.0 to ASP.NET MVC 2 Beta. I checked the breaking changes but it s not clear where the issue lies. The problem has to do with ...

Asp.net MVC Dynamic Menu System

In our current Asp.net MVC application we have 2 menu systems one accross the top and one on the left hand side. Now we have a partial view that renders the menu, however is the only way for this too ...

热门标签