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 - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -