Hi I’m working on a solution where I have two or more views that use the same model to display , edit and create.
I’ve looked in to partial views because I thought I could reuse most of the view in all of them.
now my problem lies in that I’m combining more than one partial view in the parent view and are looking to make sure that I get the post back data from all the partials in to the parent, so that I can submit or change the underlying model.
this is how I call the partials:
@using (@Html.BeginForm())
{
@Html.Partial("Person",Model.PersonDetails)
@Html.Partial("Employment", Model)
@Html.Action("Save", "Employee")
@Html.Action("Create", "Employee")
@Html.Action("Cancel", "Employee")
}
now the individual Partials contain a lot of editorfor dropdownlistfor labelfor and so on.
my question is this the correct way to reuse or is there a better and safer way to go since I’ve read and heard that it could be difficult to impossible to get the
EDIT:
I’ve been working a little further because of some unrelated problems I’ve changed the Actions to inputs like this:
<input type="submit" value="Gem" name="submitType" />
<input type="button" value="Anullere" onclick="location.href='@Url.Action("Cancel", "Employee")'" />
<input type="submit" value="Send" name="submitType" />
Edit: I’ve added another change since last I was made aware that my Send button wouldn’t send data as Post data so I changed it to be a submit button. and gave it a name to both my submit buttons.
Of course you can gather data from partial views and send them as postback data to the action which corresponds to the parent view. In your case you have to make sure that all the model fields are included in you main form for which I suppose you are making a submit. When a submit is triggered all the values from your input/select/textarea fields are collected serialized and attached to the request and on the server side all this data will be mapped to your model/action parameters which corresponds to your action.