动态添加输入以查看属性

发布于 2024-12-19 06:18:32 字数 363 浏览 1 评论 0原文

不幸的是,我对 MVC 比较陌生,所以我想做的事情可能非常简单,甚至在 MVC 中不可能。

我在库中有一系列模板类,可以在版本之间添加、更改或删除模板。我想要做的是创建一个页面,允许用户从下拉列表中选择他们希望使用的模板,然后一旦他们选择了模板,就能够通过文本框填充模板的属性、下拉列表、日期选择器等。

虽然理论上我可以为每个不同的模板创建一个视图,但我想避免这种情况,就好像可以使用较新版本的库添加/更改/删除模板一样,我会喜欢避免重写每次发生这种情况都会查看。

有谁对我如何实现这一目标有任何建议,或者知道讨论这一点的现有参考资料?

如果我错过了任何有用的信息,请告诉我。

感谢您提前提供任何帮助/建议。

萨塔尔

Unfortunately I'm relatively new to MVC so what I am trying to do might be quite simple or not even possible in MVC.

I have a series of template classes in a library which can have template added, change or removed between versions. What I am trying to do is create a page that will allow for the user to select from a drop down list which template they wish to work on and then once they have selected the template be able to populate the properties of the template through text boxes, drop down lists, date selectors etc.

Whilst I could in theory create a View for each of the different templates, I would like to avoid that as if the templates can be added/changed/removed with newer versions of the library, I would like to avoid having to rewrite the Views each time that happens.

Does anyone have any suggestions on how I might be able to achieve this or know of existing references dicussing this?

If I've missed out any information which would be of use please let me know.

Thanks for any help/advice in advance.

Satal

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月隐月明月朦胧 2024-12-26 06:18:32

无需编写代码,您所寻找的是一个组件,该组件根据传递的模型/对象构建 html,以满足通过 Web 浏览器满足该模型的需求。

我敢说这是可能的!

一个简单或更容易的途径是:

  1. 使用指示它们需要哪种输入控件的属性来装饰模板模型中的属性。

  2. 还可以使用指定属性名称的属性来装饰属性。

  3. 创建一个接受模型/类型并创建 HTML 以满足该类型输入的组件。当然,这必须在表单中呈现。

  4. 在回发/提交到您的操作时,使用 Request["{propertyName}"] 获取输入字段的值以填充属性。

  5. 您的控制器操作将接受模板的名称,以便您知道要创建哪个模型

System.ComponentModel.DataAnnotations 是一个很好的起点。

Without writing the code, what you are looking for is a component that builds html based on what model/object it is passed to satisfy the population of that model via a web browser.

I dare say that this is possible!

An easy or easier route would be:

  1. Decorate the properties within your template models with attributes that would dictate what sort of input control they require.

  2. Also decorate the properties with an attribute that specifies the name of the attribute.

  3. Create a component that accepts a model/type and creates HTML to satisfy the input of that type. Of course this must be rendered within a form.

  4. On postback/submit to your action use the Request["{propertyName}"] to get the value of input fields to populate the properties.

  5. Your controller action will accept the name of the Template so that you know which model to create

System.ComponentModel.DataAnnotations is a good place to start before writing your own custom attributes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文