Good day friends! Carefully prepared before asking a question. And so.
The task is this - there is often repeated layout code (the code itself is specially simplified, in fact, there are a lot of things because of which, in fact, the question of a more competent implementation arose). I want to make a similar Partial View:
<div id="{IDENT}"> @RenderBody </div>
We have an IDENT (identifier) and some kind of body. To further in some other View call something like this:
@using(Html.DrawMyCustomSection("ident12345")) { <b>Передать в тело</b> }
To have the output:
<div id="ident12345"> <b>Передать в тело</b> </div>
The question is in the very "elegance" of the decision. The easiest way is to refuse from Partial View in general and render everything using MvcHtmlString
. But this, it seems to me, moveton and I do not see it as a worthy option.
The second way is to use a custom helper with IDisposable implementation and PartialView rendering with replacing control lines {IDENT}
and {BODY}
with your own. This option seems to be better, but not much :)
The third way is the strictly typed model for PartialView, in which everything is transmitted. A good way, as for me. But I can’t understand how to properly transfer the body itself to PartialView and how to deploy it there.
You can also wind the implementation with ViewBag
/ ViewData
, but this is really bad.
Hence the question: How do you correctly , correctly and beautifully transfer the parameters to PartialView and render the body into the main view? Use a strongly typed model, whereas how to write (receive) into it what was in the main view is indicated in the body?
I will be glad to any answer and / or example. Thank!
ASP
, but it's nice to see well-formed questions. Keep it up! - user207618