Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

ViewData property in ViewResult is Null #2814

@aaron-hammond

Description

@aaron-hammond

HI,

I'm having a little trouble with returning a ViewResult from an orchestrator.

Where in previous versions of MVC we've done this:

    return new ViewResult
    {
        ViewName = "Index",
        ViewData = {Model = _formViewModelBuilder.BuildModel()}
    };

In MVC 6 this throws a null reference exception. Setting the model property of the ViewData is invalid as the value of ViewData is null? I believe this has something to do with dependency injection but i can't find a concrete explanation anywhere as to why this behavior is happening.

The simplest way i can get this to work is something like:

       return new ViewResult
        {
            ViewName = "Index",
            ViewData = new ViewDataDictionary<FormViewModel>(ViewData, model)
        };

This uses the Microsoft.AspNet.Mvc.Controller.ViewData property. I can pass this property through to the orchestrator but i'm not sure if this is just plain wrong and i'm missing a trick here?

Any help would be appreciated.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions