查找相关的MVC模板 [英] Find Relevant MVC Template
问题描述
我的主视图正在调用模板视图,如下所示:
My main View is calling Template view is as below:
<%: Html.EditorFor(model => model.AuthorizedCreditCard)%>
我的模板如下:
以上两个模板都使用相同的模型(即 model.AuthorizedCreditCard
).
Both above templates are consuming same model (i.e. model.AuthorizedCreditCard
).
所以我的问题是,当我调用 EditorFor
时,如何查找正在运行的模板.
So My question is How to find which Template is runing when I call EditorFor
.
我想要一个技术说明.
推荐答案
默认情况下, EditorFor
帮助器使用名称与正在编辑的类型名称匹配的模板.因此,如果您的 AuthorizedCreditCard
是名为 AuthorizedCreditCard
的实例,则应使用 AuthorizedCreditCard.ascx
.如果您想使用其他内容,则可以将所需模板的名称作为字符串传递,因此:
By default, the EditorFor
helper uses the template whose name matches the name of the type being edited. So, if your AuthorizedCreditCard
is an instance of something called AuthorizedCreditCard
, then it should use AuthorizedCreditCard.ascx
. If you want to use something else, you can pass the name of the template you want as a string, thus:
<%: Html.EditorFor(model => model.AuthorizedCreditCard, "AuthorizedCreditCardEditer")%>
这篇关于查找相关的MVC模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!