0

As I understandd MVC framework html helpers (TextBoxFor, EditorFor) use reflection for defining the names of input elements to provide reverse binding to the model. fo I got used to rather long identifier names for the sake of clarity: FirstName, LastName and many other examples.

Do standard helpers support any attribute whcih allow abstract from model member names?

For XML serialization we have attributes XmlElement, XmlAttribute where we can set the name of the element.

Thus I need something like this:

public class Person
{
    [Name("fn")]
    public string FirtsName {get;set;}

    [Name("ln")]
    public string LastName {get;set;}
}

and now call to Html.TextBoxFor( model => model.FirstName) should give <input id="fn" name="fn" type="text" value="" />

4

1 回答 1

2

标准助手是否支持任何允许模型成员名称抽象的属性?

不,他们没有。您可以编写自定义模型绑定器,或者按预期简单地命名视图模型的属性。

于 2013-04-24T06:07:23.447 回答