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.

Exception thrown when attempting to use model members in sections in a Razor Page #6294

@DamianEdwards

Description

@DamianEdwards

Repro

  1. Create a new Razor Pages project in Visual Studio
  2. Open the Index.cshtml.cs model class file
  3. Add a property to be accessed from the page's CSHTML file: public string Message { get; set; } = "Hello";
  4. Open the Index.cshtml page file
  5. Attempt to render the value of Model.Message inside the "Scripts" section:
    @section Scripts { <h1>@Model.Message</h1> }

Expected Result

The message is rendered in the HTML OK.

Actual Result

InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[System.Object]' to type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[WebApplication26.Pages.IndexModel]'. 

@rynowak @NTaylorMullen

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions