也許你應該把它存放在自己的類
public class Person
{
public string firstName { get; set; }
public SocialSecurityNumber SSN { get; set; }
}
public class SocialSecurityNumber
{
public string SSN { get; set; }
}
也許類可以有它自己的解密方法爲好。
public class SocialSecurityNumber
{
public string SSN { get; set; }
public string Decrypt()
{
//TODO: Decrypt SSN
return decrypted ssn
}
}
現在在你的控制器
[HttpPost]
public ActionResult PostedPerson (Person person)
{
string PersonName = person.firstName;
string SocialSecurityNumber = person.SSN.SSN;//or person.SSN.Decrypt();
//TODO: decrypt SocialSecurity number
}
在這種情況下,你正在使用的FormCollection的模型綁定,那麼你就必須設置某種標誌,或者使用抽象標記該字段爲加密
public class Person
{
public string firstName { get; set; }
public SocialSecurityNumber SSN { get; set; }
}
public class SocialSecurityNumber
{
public string SSN { get; set; }
public string Encrypted { get; set; }//set this to "EncryptedTrue" or something
//similar in order to handle it in the post
}
然後用你的形式收集
[HttpPost]
public ActionResult PostedPerson (FormCollection fc)
{
for(var val in fc)
{
if(val is InnerList){
{
if(val.Contains("EncryptedTrue"))
{
//then val.SSN would be an encryped social security number
}
}
}
}