Posting data back to ASP.NET MVC child actions

1.6k views Asked by At

Since we can compose a single view from a main view + a partial view (e.g. using RenderAction, specifying a child controller), is it possible for input rendered by the child action to be directed to the child controller while input rendered by the main view is directed to main view controller? At first, it seems odd to post data to two action methods, but it's consistent with the composite nature of using partial views at all.

Is this possible or practical?

1

There are 1 answers

0
Darin Dimitrov On

The location to which data is sent will depend on the action attribute of the form that contains those input elements. So when generating the form you could specify a controller and action to post to:

@using (Html.BeginForm("SomeAction", "SomeController"))
{
    ...
}

The same technique could be used for forms rendered in the main view and specify to which controller and action they should post when submitted.