ASP.NET 웹 API와 작업 : 난 내 모델 클래스와 (첫 번째 코드) 단일 dbcontext이이 프로젝트에서유효성 내가 세 가지 프로젝트가
App.Model
을
public class Customer
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
}
App.UI - MVC 프로젝트 여기
, 컨트롤러가 의 (방법을 가져 오기) 및 뷰
public ActionResult Create()
{
return View();
}
App.Validation
- ASP.NET 웹 API 프로젝트여기 검증 (Post 메소드) 전용 컨트롤러가 있습니다.
[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);
}
UI 프로젝트의 컨트롤러에서 게시 작업을 호출하면 API 프로젝트의 컨트롤러가 UI 컨트롤러의 유효성 검사를 수행합니다.
RouteConfig 및 WebApiConfig에서 라우팅 규칙을 변경해야하며 그렇지 않으면 API에 매개 변수로 동작을 전달해야합니까?
당신이 asp.net 웹 API를 응용 프로그램에 전달하려고하는 모델의 샘플이 있습니까? –
내 질문을 수정했습니다. – Mirko