0

I had a view model in that viewmodel i created two different instances using same model like this:

       public ClaimViewModel()
    {
        engineClaim = new ClaimModel();

        boatClaim = new ClaimModel();
    }

    public ClaimModel engineClaim { get; set; }

    public ClaimModel boatClaim { get; set; }

I had properties in ClaimModel like this:

    [Required]
    public string Complaint { get; set; }

    [RequiredIf("isEngineClaim", true , ErrorMessage = "Required")]
    public string Cause { get; set; }

     [Required]
    public string Correction { get; set; }

    public bool isEngineClaim { get; set; }

And in controller i am loading the index page like this

    public ActionResult Index()
    {
        ViewBag.Message = "Welcome to ASP.NET MVC!";

        ClaimViewModel claim = new ClaimViewModel();

        claim.engineClaim = new Models.ClaimModel();

        claim.engineClaim.isEngineClaim = true;

        claim.boatClaim = new Models.ClaimModel();

        claim.boatClaim.isEngineClaim = false;

        return View("Index", claim);
    }

Now my problem is the requiredif validation is not working though the 'isEngineClaim' property is different for two instances. I am following this link And moreover i had placed the hidden field of 'isEngineClaim' in my view also. But the requiredifvalidation is not working can anyone suggest me the solution.

4

0 回答 0