Reputation: 105059
As we all know RenderAction()
is either part of:
and allows us to render action result inside another view or partial view.
RenderAction()
helper.<form>
probably by using Html.BeginForm()
that postback to original view.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.
Upvotes: 0
Views: 991
Reputation: 15521
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")).
public class FormModel
{
public string Prefix { get; set; }
}
public class FormData
{
public FormModel Data1 { get; set; }
public FormModel Data2 { get; set; }
}
public ActionResult HandlePost(FormData data)
{
if (data.Data1 != null) {} else {}
}
Second way is the same but use two action parameters.
public ActionResult HandlePost(FormModel data1, FormModel data2)
{
if (data1 != null) {} else {}
}
In the partial view you do
<%= Html.TextBox(Model.Prefix + ".FormModelField", Model.FormModelField) %>
that is, you set field name with the prefix passed in the model.
Of course you may vary this in details.
Upvotes: 1