ASP.NET MVVM Handling multiple Data Transfer Objects on a single page

Posted by meffect on Programmers See other posts from Programmers or by meffect
Published on 2012-11-09T00:23:35Z Indexed on 2012/11/09 5:23 UTC
Read the original article Hit count: 250

Filed under:
|

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).

© Programmers or respective owner

Related posts about ASP.NET

Related posts about mvc