I have a fairly complex view that's almost the same for the create and edit functionality in MVC3.
Every time I change one I have to remember to make the same changes in the other.
Is there a way that I can share a view between create and edit. For example can I have t开发者_StackOverflowwo view files with different names and link them or is there another even better way.
thanks
Marcel
You could simply make a partial view with your form contents and include this partial view in your create and edit view. With that, you you are able the have some differences in your views (maybe headline "edit" / "create").
@Html.Partial("FormView")
On the other side, you could specify your view in your controller action.
public ActionResult Create()
{
return View("CreateEditView");
}
public ActionResult Edit()
{
return View("CreateEditView");
}
精彩评论