Marcel
Marcel

Reputation: 267

Can I share the same view for a create and edit in MVC3

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 two view files with different names and link them or is there another even better way.

thanks

Marcel

Upvotes: 4

Views: 1960

Answers (1)

DanielB
DanielB

Reputation: 20210

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");
}

Upvotes: 5

Related Questions