locked
How to create a ViewDataDictionary RRS feed

  • Question

  • Hello,

    I used to be able to use the ViewDataDictionary to pass parameters to my partial views:

    @Html.Partial("_myView", Model, new ViewDataDictionary { { "param1", "abc" }, { "param2", "xyz" } })

    This is the ViewDataDictionary from System.Web.Mvc.

    Now, when I start a new MVC application in Visual Studio 2017 Community Edition, and I copy and paste the above line to my new project, it defaults to the ViewDataDictionary from Microsoft.AspNetCore.Mvc.ViewFeatures. Apparently, this kind of ViewDataDictionary has no constructor that takes 0 arguments.

    According to:

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.viewfeatures.viewdatadictionary?view=aspnetcore-2.1

    There are several constructors to choose from. The simplest one for my purposes looks like this one:

    ViewDataDictionary(IModelMetadataProvider, Type)

    But I don't know what an IModelMetadataProvider is or how to create one. Same with Type.

    Can anyone link me to some simple example of how one creates a ViewDataDictionary along with an IModelMetadataProvider and Type? Nothing too complicated, something that would fit nicely on one line (i.e. in the @Html.Partial(...) above).

    Thanks.
    • Moved by CoolDadTx Friday, June 22, 2018 1:39 PM ASP.NET related
    Friday, June 22, 2018 3:18 AM

All replies

  • Please post questions related to MVC in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, June 22, 2018 1:39 PM