dimanche 14 juin 2015

MVC3 POST model binding not working for particular complex model

For some reason, when I post this view model back to the controller and add in the model for binding, it ends up being null. The application that I am working with is a massive one. Also I haven't written much of the code so this model is massive so I will just add the parts that matter, but could other properties be preventing the model binding?

I do know that it has been working but in the last little bit it started not. Maybe it's not even something with the model, would just love some help debugging it.

--- GET Action ---
[HttpGet]
    public ActionResult Categories(int applicationId)
    {
        ...other code.....

        // Get the application
        var application = _sqsApplicationService.Load(applicationId);
        var model = SqsApplicationViewModel.MapFromDto(application);

        // Setup the categories for display and choosing
        var categories = _sqsCategoryService.Load();
        var cats = SqsCategoryViewModel.MapFromDto(categories);
        model.SetupCategoriesForSelection(cats);

        return View(model);
    }

-

--- POST action --
[HttpPost]
    public ActionResult Categories(int applicationId, SqsApplicationViewModel model)
    {
        // Save away the ids they chose
        _sqsApplicationCategoryService.SaveCategories(applicationId, model.Display_Categories.Where(i => i.Selected).Select(i => i.CategoryId).ToList());

        // Complete the step
        _sqsApplicationStepService.CompleteStep(applicationId, SqsStep.Categories);

        return RedirectToAction("Documents");
    }

-

public class SqsApplicationViewModel : IMappable
{
    public int Id { get; set; }
    public int SupplierId { get; set; }
    public int? SqsApprovalLevelId { get; set; }

    .... other properties .....

    public List<SqsChosenCategoryViewModel> Display_Categories { get; set; }

    .... other properties .....
}

-

public class SqsChosenCategoryViewModel
{
    public int CategoryId { get; set; }
    public string Name { get; set; }
    public string CategoryAmountString { get; set; }
    public bool Selected { get; set; }

    public IList<SqsDocumentComplianceViewModel> Documents { get; set; }
}

Aucun commentaire:

Enregistrer un commentaire