I'm new to MVC 3 and I have a question regarding the correct approach.
Imagine I have a model:
public class MyCustomModel
{
[Required]
public string UserName { get; set; }
[Required]
public DateTime? Birthdate { get; set; }
[Required]
public string City {get;set;} //To partial view
[Required]
public string Street {get;set;} //To partial view
}
And here I have a view
@Html.TextBoxFor(m => m.UserName) @Html.TextBoxFor(m => m.BirthDate) @Html.Action("LocationGroup", "Home") //In this should the city and street be rendered
My Partial View will have somethign like that: @Html.TextBoxFor(m => m.City) @Html.TextBoxFor(m => m.Street)
And this the action in the controller:
[ChildActionOnly]
public ActionResult LocationGroup()
{
MyCustomModel model = new MyCustomModel (); //Should i really instantiate a new instace of the model??? and pass it to the partial view
return PartialView("_TempView", model);
}
Basically my general view will have all the field with texboxex, but now in my partial view i also would like to have few of those propeties from my model be rendered correctly and after submiting the form should be available in the same model as all other properties.
So my question, in the action which send the partial view back, should i really instantiate a new instace of the model? But then the data will be split between 2 instances of the model no?
How to arrange that, how can i then ass the data to the general views model from partial view?