views:

21

answers:

1

I need following attributes:

1.For example: i have 2 field. first is checkbox, second is textbox. If first control checked. second field must be Required attribute. first control unchecked. second control not required.

[Required]
public boolean showHeader{get;set;}

[IFRequired("showHeader",true)]
public string HeaderText{get;set;}

2.For example: i have 2 field. new password, confirmation password. Attribute must check this 2 field are equal.

[Required]
public string newPassword{get;set;}

[Expression("newPassword",ExpressionAttributeEnum.Equils)]
public string confirmPassword{get;set;}

How to create above attributes?

A: 

This is not possible using attributes.

however you can do it quite easy in your action.

public ActionResult Create(FormCollection collection) {
    ///do your checks here which you cant do using attributes
    ModelState.AddModelError("fieldname", "yourErrorMessage");

    if (ModelState.IsValid) {
        ////.........
    }
    return View();
}
Stefanvds