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

AspNetCore Model property values null on POST only when action parameter is called “model” #8230

Closed
devfunkd opened this issue Aug 7, 2018 · 2 comments

Comments

@devfunkd
Copy link

devfunkd commented Aug 7, 2018

Is this a Bug or Feature request?:

Bug

Steps to reproduce (preferably a link to a GitHub repo with a repro project):

  • Using built-in scaffolding, create a new CRUD controller binding to model.
  • Change parameter name on POST action to "model"
  • Attempt to post data back to the controller

Description of the problem:

Did something change in AspNetCore that no longer allows you to use the parameter name "model" on POST actions?

If I do this, the DeviceModel property values are populated on postback:

[HttpPost] 
public IActionResult Create(DeviceModel **device**)

However if I change the parameter name from "device" to "model" the property values are null.

[HttpPost]
public IActionResult Create(DeviceModel **model**)
Is this a bug in AspNetCore or did they change something?

I can't find anything saying that the parameter can't be called "model" and in previous MVC versions this worked fine.

Version of Microsoft.AspNetCore.Mvc or Microsoft.AspNetCore.App or Microsoft.AspNetCore.All:

CompatibilityVersion.Version_2_1

@devfunkd
Copy link
Author

devfunkd commented Aug 7, 2018

https://stackoverflow.com/questions/51735929/model-property-values-in-aspnetcore-2-1-are-null-on-post-when-action-parameter-i

Seems having a property in my model called "Model" breaks the postback data. I removed the property and the postback works. Why would a property being named "Model" in my model break the postback action?

@pranavkm
Copy link
Contributor

pranavkm commented Aug 7, 2018

Unfortunately this is by design. See #3735. We're going to try using an analyzer to provide some tooling guidance in this scenario.

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

No branches or pull requests

2 participants