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

JSON naming strategy not being applied to @model #7166

Closed
simpadat opened this issue Dec 29, 2017 · 4 comments
Closed

JSON naming strategy not being applied to @model #7166

simpadat opened this issue Dec 29, 2017 · 4 comments

Comments

@simpadat
Copy link

simpadat commented Dec 29, 2017

I'm in the process of updating a MVC website to .Net Core and run into this issue: #4842

Which is fine. I applied the fix to get the proper serialisation, but ran into an issue where passing a model to a page via @model. The property names are being camelCased even though I've told MVC to use the DefaultContractResolver.

Startup.cs:

    services
        .AddMvc()
        .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

Model

    public class Grade
    {
        public int Id { get; set; }
        public string Description { get; set; }
    }

Controller

        public ActionResult EditGrade(int id)
        {
            var grade = _service.LoadGrade(id);
            return View("GradeEdit", grade);
        }

View

@model Grade

Browser

{id: 20, description: 'Test Data'}
@mkArtakMSFT
Copy link
Member

@simpadat, can you please share the full project with a repro?

@simpadat
Copy link
Author

I've created a simple reproduction of the issue here: https://github.com/simpadat/TestMvcNaming

Hopefully not just a combination of using React.ASPNET with MVC...

@John0King
Copy link

I believe it's an issure of React.AspNet

@mkArtakMSFT
Copy link
Member

@simpadat, this indeed looks like an issue with React.AspNet. You should file a new issue with the owners of that package: https://github.com/reactjs/react.net

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants