I would like to do something like this:
<!--#include file="../stuff/foo/box.aspx"-->
But doing this in an ASP.Net MVC application it just feels wrong. Is there a better way of achieving the same thing in a ASP.Net MVC project ?
<%: Html.Partial("~/Views/foo/box.ascx") %>
or:
<% Html.RenderPartial("~/Views/foo/box.ascx"); %>
or the best of them all use an editor template (if this partial contains inputs for editing the view model property):
<%: Html.EditorFor(x => x.MyModelProperty) %>
or a display template (if this partial contains only display of view model property):
<%: Html.DisplayFor(x => x.MyModelProperty) %>
and their Razor equivalence
@Html.Partial("~/Views/foo/box.ascx")
@{Html.RenderPartial("~/Views/foo/box.ascx");}
@Html.EditorFor(x => x.MyModelProperty)
@Html.DisplayFor(x => x.MyModelProperty)
You should make a partial view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With