Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Models repeated for both web app and web API?

$
0
0

I am busy creating an ASP .Net MVC 1.1 Web App. This will server as the front end. I am also creating an ASP .Net MVC 1.1 Web API. This will server as the back end to the web app, as well as to a phone app that a colleague is developing.

My question is, the web app and web API share many of the same models. For example, in a car dealership, the web app might have a form to add a new car. The user would fill in all the fields in the form and hit submit. The web app would then perform an HTTP POST to the Web API, passing this car model to the Web API controller, which would receive the car model as a parameter. So, in this case, both web app and web API would have a copy of the car model.

What is the correct way to handle this? Do I need to have a car model in the "Models" folder of both my web app project and my web API project in the "Car Dealership" solution? And if I have to add a field (such as mileage) I would add it to both models (as well as to the database and to the HTML form)? Is there no way to share models? I just want to make sure I'm doing things correctly - I'm very new to ASP .Net (and web development in general)

Thanks


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>