ASP.NET MVVM Handling multiple Data Transfer Objects on a single page
- by meffect
I have an asp.net mvc "edit" page which allows the user to make edits to the parent entity, and then also "create" child entities on the same page. Note: I'm making these data transfer objects up.
public class CustomerViewModel
{
public int Id { get; set; }
public Byte[] Timestamp { get; set; }
public string CustomerName { get; set; }
public etc..
public CustomerOrderCreateViewModel CustomerOrderCreateViewModel { get; set; }
}
In my view I have two html form's. One for Customer "edit" Http Posts, and the other for CustomerOrder "create" Http Posts. In the view page, I load the CustomerOrder "create" form in using:
<div id="CustomerOrderCreate">
@Html.Partial("Vendor/_CustomerOrderCreatePartial", Model.CustomerOrderCreateViewModel)
</div>
The CustomerOrder html form action posts to a different controller HttpPost ActionResult than the Customer "edit" Action Result.
My concern is this, on the CustomerOrder controller, in the HttpPost ActionResult
[HttpPost]
public ActionResult Create(CustomerOrderCreateViewModel vm)
{
if (!ModelState.IsValid)
{
return [What Do I Return Here]
}
...[Persist to database code]...
}
I don't know what to return if the model state isn't valid. Right now it's not a problem, because jquery unobtrusive validation handles validation on the client. But what if I need more complex validation (ie: the server needs to handle the validation).