MarwaAhmad
MarwaAhmad

Reputation: 874

razor view a lone and inside another razor view, what is the best practice?

I'm currently working on an ASP.Net MVC project and i'm using razor views. I've a controller's action; say action A which has its own razor view; say view A.

Also, i have another controller's action; action B, and has its own razor view; view B.

Now, i want to have the razor view A inside the razor view B; instead of copying all the view A contents in view B to avoid repeated code.

What do you suggest?

any idea would be appreciated.

Upvotes: 0

Views: 127

Answers (2)

Manoj
Manoj

Reputation: 6000

if there is no model to pass then Inside B.cshtml call (do not need .cshtml)

@Html.Partial("A")

with model

@Html.Partial("A", @Model.SubModel)

Upvotes: 1

James
James

Reputation: 82096

Inside B.cshtml call

@Html.Partial("A.cshtml", modelForA)

Upvotes: 2

Related Questions