在ASP.NET MVC中扩展HiddenFor模板 [英] Extend HiddenFor Templates in ASP.NET MVC

查看:98
本文介绍了在ASP.NET MVC中扩展HiddenFor模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为Html.HiddenFor可以使用Html.DisplayForHtml.EditorFor之类的模板.不幸的是,该方法不像其他方法那样接受TemplateName.

I thought Html.HiddenFor could use Templates like Html.DisplayFor or Html.EditorFor. Unfortunately the method doesn't accept a TemplateName like the others.

我知道,解决方法是使用具有HiddenFors的DisplayFor/EditorFor模板.但我想找出如何扩展Html.HiddenFor方法.有人吗?

I know, the workaround would be to use a DisplayFor/EditorFor Template which has HiddenFors. But I would like to find out how to extend the Html.HiddenFor method. Anyone?

致谢

推荐答案

似乎您被错误的类比误导了. HiddenFor<input type="hidden"/>标记完全对应.就像TextBoxForCheckBoxFor等一样.这些方法并非旨在使用模板.另一端的DisplayFor/EditorFor是专门创建的,可与项目中定义的模板一起使用.因此,您所要求的是无法即用的.

Seems like you are mislead by wrong analogy. HiddenFor corresponds exactly to the <input type="hidden"/> tag. Just like TextBoxFor, CheckBoxFor etc. These methods are not designed to use templates. DisplayFor/EditorFor on the other side are specially created to be used with templates defined in the project. Thus what you are asking for is not possible out-of-the-box.

但是,您始终可以使用任何参数集和所需的逻辑为HiddenFor定义自己的重载.

However you can always define your own overload for HiddenFor with whatever set of parameters and whatever logic you might require.

这篇关于在ASP.NET MVC中扩展HiddenFor模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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