As we all know RenderAction()
is either part of:
- Asp.net MVC 1 Futures or
- Asp.net MVC 2 Beta 2
and allows us to render action result inside another view or partial view.
Description
- You have a view with multiple partial views displayed using
RenderAction()
helper. - At least two partial views render a
<form>
probably by usingHtml.BeginForm()
that postback to original view. - Postback is not performed via Ajax call
- Postback data is validated upon form POST.
Problem
When one of the forms gets posted back the other one renders as invalid.
Has anyone used this pattern and solved it? We should somehow know which form
performed postback and only that one should validate its POST data. Others should either ignore validation or perform regular HttpVerb.Get
action processing.
Have a hidden field in the form to indicate which one. Or, have a prefix passed to the partial and appended to each element in the form.
About prefixes. First way is to have two properties, calling Html.RenderPartial("partial", Model.Data1/2.WithPrefix("data1")).
Second way is the same but use two action parameters.
In the partial view you do
that is, you set field name with the prefix passed in the model.
Of course you may vary this in details.