Here is my Complex ViewModel
public class OperationStudyInputViewModel
{
public OperationStudy OperationStudy { get; set; }
public FileUpload FileUploads { get; set; }
public IEnumerable<string> Attachments { get; set; }
public IEnumerable<string> Folders { get; set; }
}
Here is the OperationStudy Model
public class OperationStudy
{
public int OperationStudyId { get; set; }
public string SpCategoryId { get; set; }
//Here is some Other Properties
}
Here is the OperationStudyInput() Post Method
[HttpPost]
public ActionResult OperationStudyInput([Bind(Exclude = "SpCategoryId")] OperationStudyInputViewModel inputViewModel, IEnumerable<HttpPostedFileBase> multiplefiles)
{
// some Necessary codes Here
_dbContext.OperationStudies.Add(inputViewModel.OperationStudy);
_dbContext.SaveChanges();
}
I want to exclude SpCategoryId From OperationStudy in inputViewModel(inputViewModel.OperationStudy) in OperationStudyInput() Post mehtod. I have tried with the previous code but its not working as expected!!
Any Help Please!!
OperationStudyand omit theOperationStudyIdproperty. (and when you use a view model you never need a[Bind]attribute - that's one of the many reasons why you use a view model.[Bind(Exclude = "OperationStudy.SpCategoryId")]