如何在MVC 2使用Html.EditorFor时设置外观字段顺序? [英] How to set order of appearance for fields when using Html.EditorFor in MVC 2?

查看:135
本文介绍了如何在MVC 2使用Html.EditorFor时设置外观字段顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下类在我的模型:

I have the following classes in my Model:

public abstract class Entity : IEntity
{
    [ScaffoldColumn(false)]
    public int Id { get; set; }
    [Required,StringLength(500)]
    public string Name { get; set; }
}

public class Model : SortableEntity
{
    [Required]
    public ModelType Type { get; set; }
    [ListRequired]
    public List<Producer> Producers { get; set; }
    public List<PrintArea> PrintAreas { get; set; }
    public List<Color> Colors { get; set; }
}

要在视图中显示模型类我只需调用Html.EditorFor(型号=>模型),但基类上次渲染,这是不期望的行为的名称属性。

To display the "Model" class in the view I simply call Html.EditorFor(model=>model), but the "Name" property of the base class is rendered last, which is not the desired behaviour.

是否有可能以某种方式influenece显示的字段的顺序?

Is it possible to influenece on the order of displayed fields somehow?

推荐答案

我已经无法找到一个属性,让你的选择是:

I've not been able to find an attribute for that, so your options are:

1)创建一个,然后修改基Object.ascx模板占它,或
2)为您的类,明确提出的东西,在你希望的顺序一个自定义编辑器模板。

1) create one, and then revise the base Object.ascx template to account for it, or 2) create a custom editor template for your classes that explicitly put stuff in the order you want.

这篇关于如何在MVC 2使用Html.EditorFor时设置外观字段顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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