0

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

2
Contributors
1
Reply
5
Views
3 Years
Discussion Span
Last Post by LastMitch
0

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; }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.