而不是直接使用對象,在一個簡單的剃刀視圖我有一個窗體使用,因爲它+ s model
一個裝飾器對象。模型不適用DataType.Password
public class GlobalAccount
{
public GlobalAccount()
{
this.TestService = new TestServiceModel();
}
public TestServiceModel TestService { get; set; }
}
beeing TestServiceModel
表示
public class TestServiceModel
{
[Required]
[Display(Name = "Endpoint (url of your service like http://mydomain/remote/)")]
public string Endpoint { get; set; }
[Required]
[Display(Name = "System username")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "System password")]
public string Password { get; set; }
}
注意的Password
財產與DataType.Password
,並在Partial Razor view
裝飾我有一個調用該對象
@model OnlineServices.Administration.Models.GlobalAccount
...
@Html.TextBoxFor(model => model.TestService.Password, new { size = "30" })
的問題是,在html
我得到的type="text"
代替text="password"
可以在this image看到整個流程:
我是什麼失蹤在這裏嗎?
愚蠢的我......這麼簡單,但如此遙遠!我只是忽略它......總是在考慮模型中的錯誤,並且從來沒有親眼看到: -/**我需要休假!**:o) – balexandre 2011-05-18 12:54:35
很容易錯過。 – Kieron 2011-05-18 13:08:13
請考慮使用Html.PasswordFor(請參閱下面的@Skuld答案) – 2012-02-10 22:56:00