c# - Have Required Attribute apply to property in one view and not another? -


say have class called test , have create , edit view. class incredibly simple

public class test {     [required]     public string str { get; set; } } 

is possible remove required attribute when user editing object?

viewmodels there this. 1 create , 1 edit.

you should use viewmodel this, need view specific models here :

public class createtestviewmodel {     [required]     public string str { get; set; } } 

and:

public class edittestviewmodel {     public string str { get; set; } } 

you might want read what viewmodel in mvc , how use viewmodel in mvc


Comments

Popular posts from this blog

javascript - Knockout pushing observable and computed data to an observable array -

Trouble making a JSON string -

sitecore - Resolve ISitecoreService using SimpleInjector -