I have the following model:
public class CaseFormViewModel
{
public int ID { get; set; }
public int AppID { get; set; }
public CaseGeneralFormViewModel General { get; set; }
public CaseMedicalFormViewModel Medical { get; set; }
public CaseLegalFormViewModel Legal { get; set; }
public CaseCommentsFormViewModel Comments { get; set; }
public List<UploadedDocumentModel> Attachments { get; set; }
public string AzureStorage { get; set; }
}
public class CaseGeneralFormViewModel : CaseGeneralViewModelBase
{
[Required]
public new string PatientName { get; set; }
also I have a view with model CaseFormViewModel and have a Partial View with model CaseGeneralFormViewModel. View loads this partial View:
@Html.Partial("PartialCaseGeneralForm", Model.General)
Partial View has the following string:
@Html.ValidationMessageFor(model => model.PatientName)
then, when I post this view to the controller method:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult UpdateCase(int AppID, CHFN.Models.CaseFormViewModel model)
{
model.General is null. I understand why, because PatientName should have id="General.PatientName" instead of id="PatientName", but how can I add that prefix to the all elements on page?
I see some ability to do it : modify post controller method to:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult UpdateCase(int AppID, CaseGeneralFormViewModel general)
{
but first at all, code is dirty (structure of internal classes are broken), secondly - any class (i.e. CaseGeneralFormViewModel) can have 2 properties of the same class (i.e.
public Class1 Prop1 { get; set; }
public Class1 Prop2 { get; set; }
). How to solve it - I don't know....
Solution is:
Create an extention method for Partial:
and use: