在ASP.NET MVC 4用户控制等效 [英] User Control Equivalent in ASP.NET MVC 4

查看:110
本文介绍了在ASP.NET MVC 4用户控制等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个新的ASP.NET MVC应用程序4。我真的想要做的事情MVC的方式。特别是,我很感兴趣,使用的Razor视图引擎。请注意,我来自一个Web表单的背景,所以我的问题似乎很尴尬。

I'm working on a new ASP.NET MVC 4 app. I'm really trying to do things the "MVC" way. In particular, I'm interested in using the Razor view engine. Please note that I come from a web forms background, so my questions may seem awkward.

我想了解是否有一些相当于用户控件在MVC?如果是这样,他们在叫什么?如果没有,什么是推荐的方式在MVC创建可重用的组件?

I'm trying to learn if there is something equivalent to user controls in MVC? If so, what are they called? If not, what is the recommended way to creating a reusable component in MVC?

感谢您

推荐答案

您正在寻找 @ Html.Action @ Html.Partial

他们让您无论是渲染的局部视图或一个完全成熟的<一个href=\"http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/creating-an-action-cs\">controller行动在视图中的。这是重用的MVC土地的通用模式。

They allow you to either render a partial view or a full blown controller action in a view. This is a common pattern of reuse in MVC land.

有时候你会想使<一个href=\"http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html\">displayFor或editorFor模板,如果一个控制器动作太重了。经验法则是,如果你需要多次做网页上,它需要在表单中调回,想想在模板中做这件事。

Occasionally you would want to make displayFor or editorFor templates, if a controller action is too heavy. The rule of thumb is if you need to do it multiple times on the page and it needs to be posted back in a form, think about doing it in a template.

在asp.net控件覆盖相当大的大片这MVC granularizes多一点。

Controls in asp.net cover a rather large swath which MVC granularizes a bit more.

这篇关于在ASP.NET MVC 4用户控制等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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