开发者

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

开发者 https://www.devze.com 2023-03-06 16:26 出处:网络
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.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号