开发者

Posting data back to ASP.NET MVC child actions

开发者 https://www.devze.com 2023-04-13 01:24 出处:网络
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 t

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 d开发者_开发技巧irected 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号