I am new to .Net MVC.
Currently due to server specification, i am using MVC 4 and Visual Studio 2012 for Web.
I am using entity framework for CRUD operation.
My problem is, i am a bit confused with how to specify different validation rules for create and edit operation:
My class is something like this: public class Outlet { [Key] public int outletID { get; set; }
[Required]
[StringLength(10)]
public string outletCode { get; set; }
[Required]
[StringLength(100)]
public string outletName { get; set; }
[Required]
[StringLength(50)]
public string outletAreaManager { get; set; }
[Required]
[StringLength(200)]
public string outletAddress { get; set; }
[StringLength(20)]
public string outletUnitNo { get; set; }
[Required]
[StringLength(6)]
public string outletPostalCode { get; set; }
[StringLength(10)]
public string outletPhoneNo { get; set; }
}
When the user create new outlet, they are able to key in all the field, but when do want to edit the outlet, some field like OutletCode, outletAreaManager is uneditable and not displayed in the form and due to some security reason, i couldn't store it in the hiddenfield, what is the best way to do it? I means how to code it when updating to database? if i use ModelState.isValid, it will trigger the required attribute for outletCode and outletAreaManager.
Thanks in advance.