In my solution i have three projects:
App.Model
In this project i have my models class and a single dbcontext (code first)
public class Customer
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
}
App.UI - MVC Project
Here, there are the controllers (Get method) and views
public ActionResult Create()
{
return View();
}
App.Validation - ASP.NET Web API Project
Here there are only controllers for validation (Post method).
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="ID,Name")] Customer customer)
{
if (ModelState.IsValid)
{
db.Customer.Add(customer);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(customer);
}
When I call a post action from a controller in the UI project, I would the controller in API project perform validation of the UI Controller.
I have to change the routing rules in RouteConfig and WebApiConfig or I need pass the action as a parameter to the API?