I have been trying to get a single model, with multiple partail views that use that model to sumbit the form correctly.

@Html.Partial("_EmployerDetails", Model)
<br />
@Html.Partial("_OutcomeControl", Model)

When I submit the form only the firt PatailView model is posted. The second partailview values is null. I need to modulize my partail view but this have been nightmare. Got it work if a map hiddenvlaues on the main view to the model. But this is not what I want to do.

I want the partailView to act like a userControl in webforms.

Any idees?

Kind regards
Singlem

Member Avatar for LastMitch

When I submit the form only the firt PatailView model is posted. The second partailview values is null. I need to modulize my partail view but this have been nightmare. Got it work if a map hiddenvlaues on the main view to the model. But this is not what I want to do.

@Singlem

I don't know what is your public class because you didn't provide enough info to really see the issue. Plus I don't know what is your pulbic class looks like but what is Model? Your Model should have a unique values.

This is your code:

@Html.Partial("_EmployerDetails", Model)
<br />
@Html.Partial("_OutcomeControl", Model)

It should look like this:

@model YourViewModel
@Html.LabelFor(model => model.Title);
@Html.EditorFor(model => model.Title);
@Html.ValidationMessageFor(model => model.Title);

@{Html.Partial("_EmployerDetails", new YourViewModel());}
@{Html.Partial("_OutcomeControl", new YourViewModel());}

public class YourViewModel
{
[Required]
[DataType(DataType.Text)]
public String Title { get; set; }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.