A
A
Alexander Sulimov2015-04-13 13:08:29
ASP.NET
Alexander Sulimov, 2015-04-13 13:08:29

MVC 5 WebApi binding how to do it right?

It is required to write a lot of ApiController
The problem is that the models do not match
I have a model
public Model
{
public string Name { get; set; }
}
and Post comes (cannot change the request)
Name: ""
model: "objects"
name: "New"
I found that this transformation can be solved through IModelBinder
public Model Post([ModelBinder(typeof(ModelBinder))] Model model) I get
into bool BindModel (..)
but I can’t reach the parameters that came in.
Tell me a simple way to bind models if their fields do not match
and / or
how to create a Model with Name = name in BindModel

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RouR, 2015-04-23
@RouR

Bind the models the way they come. These will be your API models.
Then work either with them directly or do remapping in the database model.

V
vikramjkn, 2020-07-25
@vikramjkn

You can check how model bindings works in MVC
https://qawithexperts.com/article/asp.net/model-bi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question