asp.net mvc - MVC4 Conditional Required Annotation -
I have assets which are required through data annotations to work perfectly, to form this form, but I do not want to make this property necessary for editing. How can I go about doing this?
You can create different visual models to create and edit scenes. Class and get the succession of those 2 visual models of that general category.
public class customer view model {public string name {set; Get;} public string locale {set; Public class CreateCustomer: CustomerViewModel {[Required] Public String LastJobTitle {set; Get;}} public class EditCustomer: CustomerViewModel {public string LastJobTitle {set; Get;}} and you can use them in this manner in your methodology
create public actions () {var createVM = New CreateCustomer (); See return (createVM); } Edit Public Functionality (id) {var editVM = New EditCustomer (); Var Customer Model = Repository Gate Customer (ID); EditVM.LastJobTitle = customerModel.LastJobTitle; // set also return other attributes (createVM); } Then your Create view will be typed strongly for the CreateCustomer category and typed strongly in the edit code in the EditCustomer category Will go Create.cshtml @Model CreateCustomer Edit.cshtml @ Modal editing client
Comments
Post a Comment