Question

This is a follow up to this: What does MVC3 do with C# Optional Parameters?

I have an action with the following signature:

public ViewResult Show(int Id, PublishingErrorSummary pubErrors=null, String title=null)

On requesting server/show/1 pubErrors is not null, but title is null. How is it possible? These are just two objects but string somehow manages to become null. Where can I fix this?

Edit: class definition added

public class PublishingErrorSummary
{
    public List<string> StepOneErrors { get; set; }
    public List<string> StepTwoErrors { get; set; }
    public List<string> StepThreeErrors { get; set; }
    public List<string> StepFourErrors { get; set; }
}
Was it helpful?

Solution

PublishingErrorSummary is a complex object. The default model binder always initializes complex objects. It doesn't really make sense to set its default value to null. Same stands for the title parameter. Strings are reference types and their default value will be null anyway if no request parameter title is sent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top