How to reference a global virtual include in MVC?2019 Community Moderator ElectionWhat is the right way to '#include file' in MVC?How to cache data in a MVC applicationMigrating Classic ASP - Webforms or ASP.NET MVC?How to include a partial view inside a webformASP.NET MVC - Set custom IIdentity or IPrincipalASP.NET MVC - Find Absolute Path to the App_Data folder from Controllerasp.net mvc - strategy for including SEO information such as meta keywords and descriptionsFile Upload ASP.NET MVC 3.0How to Include Add'l .js from an ASP.NET MVC View? (.aspx)How to include contents of plain HTML or classic ASP file in an ASP.net MVC 3 view?Where to set the layout globally in MVC application
In Aliens, how many people were on LV-426 before the Marines arrived?
Unfrosted light bulb
Can you move over difficult terrain with only 5 feet of movement?
What does Jesus mean regarding "Raca," and "you fool?" - is he contrasting them?
Relation between independence and correlation of uniform random variables
How are passwords stolen from companies if they only store hashes?
Usage and meaning of "up" in "...worth at least a thousand pounds up in London"
Is there a term for accumulated dirt on the outside of your hands and feet?
How to generate binary array whose elements with values 1 are randomly drawn
I got the following comment from a reputed math journal. What does it mean?
Describing a chess game in a novel
Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?
gerund and noun applications
Recruiter wants very extensive technical details about all of my previous work
How to define limit operations in general topological spaces? Are nets able to do this?
World War I as a war of liberals against authoritarians?
Matrix using tikz package
Fewest number of steps to reach 200 using special calculator
Do I need to consider instance restrictions when showing a language is in P?
How to terminate ping <dest> &
What exactly term 'companion plants' means?
Do native speakers use "ultima" and "proxima" frequently in spoken English?
Brake pads destroying wheels
Hausdorff dimension of the boundary of fibres of Lipschitz maps
How to reference a global virtual include in MVC?
2019 Community Moderator ElectionWhat is the right way to '#include file' in MVC?How to cache data in a MVC applicationMigrating Classic ASP - Webforms or ASP.NET MVC?How to include a partial view inside a webformASP.NET MVC - Set custom IIdentity or IPrincipalASP.NET MVC - Find Absolute Path to the App_Data folder from Controllerasp.net mvc - strategy for including SEO information such as meta keywords and descriptionsFile Upload ASP.NET MVC 3.0How to Include Add'l .js from an ASP.NET MVC View? (.aspx)How to include contents of plain HTML or classic ASP file in an ASP.net MVC 3 view?Where to set the layout globally in MVC application
My company has a set of global virtual files that they want to use for the look and feel of the site. In the ASP days you would use #include virtual="etc". These are files outside of the application.
In ASP.NET you could use something like Response.WriteFile...
But if I try that in an MVC View then I get the content always at the top of the page, not where I want it in position.
How would I approach doing this in ASP.NET MVC?
asp.net-mvc
add a comment |
My company has a set of global virtual files that they want to use for the look and feel of the site. In the ASP days you would use #include virtual="etc". These are files outside of the application.
In ASP.NET you could use something like Response.WriteFile...
But if I try that in an MVC View then I get the content always at the top of the page, not where I want it in position.
How would I approach doing this in ASP.NET MVC?
asp.net-mvc
1
Have you seen this post: stackoverflow.com/questions/5021763/…
– David Tansey
Mar 7 at 17:11
@DavidTansey: That's pretty old. Is it still the canonical way to do it?
– Robert Harvey♦
Mar 7 at 17:14
Ahhh, that could work as well. I didn't think you could reference .ascx files within a PartialView if you're using Razor as your view engine. See how I did it below. Yes, it looks like a kluge but actually works. I'll look at your solution as well. Actually that solution you posted wouldn't work for me because the includes have to be located in a central location well outside of the directory structure of the application. Since someone may change content in the include globally, if I had the content within the application, I wouldn't be picking up the changes.
– Charles Owen
Mar 9 at 2:12
add a comment |
My company has a set of global virtual files that they want to use for the look and feel of the site. In the ASP days you would use #include virtual="etc". These are files outside of the application.
In ASP.NET you could use something like Response.WriteFile...
But if I try that in an MVC View then I get the content always at the top of the page, not where I want it in position.
How would I approach doing this in ASP.NET MVC?
asp.net-mvc
My company has a set of global virtual files that they want to use for the look and feel of the site. In the ASP days you would use #include virtual="etc". These are files outside of the application.
In ASP.NET you could use something like Response.WriteFile...
But if I try that in an MVC View then I get the content always at the top of the page, not where I want it in position.
How would I approach doing this in ASP.NET MVC?
asp.net-mvc
asp.net-mvc
asked Mar 7 at 17:04
Charles OwenCharles Owen
70367
70367
1
Have you seen this post: stackoverflow.com/questions/5021763/…
– David Tansey
Mar 7 at 17:11
@DavidTansey: That's pretty old. Is it still the canonical way to do it?
– Robert Harvey♦
Mar 7 at 17:14
Ahhh, that could work as well. I didn't think you could reference .ascx files within a PartialView if you're using Razor as your view engine. See how I did it below. Yes, it looks like a kluge but actually works. I'll look at your solution as well. Actually that solution you posted wouldn't work for me because the includes have to be located in a central location well outside of the directory structure of the application. Since someone may change content in the include globally, if I had the content within the application, I wouldn't be picking up the changes.
– Charles Owen
Mar 9 at 2:12
add a comment |
1
Have you seen this post: stackoverflow.com/questions/5021763/…
– David Tansey
Mar 7 at 17:11
@DavidTansey: That's pretty old. Is it still the canonical way to do it?
– Robert Harvey♦
Mar 7 at 17:14
Ahhh, that could work as well. I didn't think you could reference .ascx files within a PartialView if you're using Razor as your view engine. See how I did it below. Yes, it looks like a kluge but actually works. I'll look at your solution as well. Actually that solution you posted wouldn't work for me because the includes have to be located in a central location well outside of the directory structure of the application. Since someone may change content in the include globally, if I had the content within the application, I wouldn't be picking up the changes.
– Charles Owen
Mar 9 at 2:12
1
1
Have you seen this post: stackoverflow.com/questions/5021763/…
– David Tansey
Mar 7 at 17:11
Have you seen this post: stackoverflow.com/questions/5021763/…
– David Tansey
Mar 7 at 17:11
@DavidTansey: That's pretty old. Is it still the canonical way to do it?
– Robert Harvey♦
Mar 7 at 17:14
@DavidTansey: That's pretty old. Is it still the canonical way to do it?
– Robert Harvey♦
Mar 7 at 17:14
Ahhh, that could work as well. I didn't think you could reference .ascx files within a PartialView if you're using Razor as your view engine. See how I did it below. Yes, it looks like a kluge but actually works. I'll look at your solution as well. Actually that solution you posted wouldn't work for me because the includes have to be located in a central location well outside of the directory structure of the application. Since someone may change content in the include globally, if I had the content within the application, I wouldn't be picking up the changes.
– Charles Owen
Mar 9 at 2:12
Ahhh, that could work as well. I didn't think you could reference .ascx files within a PartialView if you're using Razor as your view engine. See how I did it below. Yes, it looks like a kluge but actually works. I'll look at your solution as well. Actually that solution you posted wouldn't work for me because the includes have to be located in a central location well outside of the directory structure of the application. Since someone may change content in the include globally, if I had the content within the application, I wouldn't be picking up the changes.
– Charles Owen
Mar 9 at 2:12
add a comment |
1 Answer
1
active
oldest
votes
I actually got this to work. I HAD to work with these old virtual includes, I had no choice for the company.
I did this in the layout: I basically had to inject the includes with a Response.WriteFile to the place up the directory tree where the includes were located. These includes are used for ALL web sites in our company. Then I used a StringBuilder to build the content within the layout. I also had to put the @RenderBody statement within the Response object as well.
@using System.Text;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple."/>
<meta name="title" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple." />
<meta name="robots" content="index, follow" />
<meta name="keywords" content="software, training, Android, mobile, iOS, Apple, data, visualization" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link rel="icon" href="~/Content/favicon3.ico" type="image/x-icon" />
</head>
<body>
@
Response.Buffer = false;
Response.BufferOutput = false;
Response.WriteFile("../../includes/header.inc");
StringBuilder sb = new StringBuilder(4000);
sb.Append("<div class="container body-content">");
sb.Append(@RenderBody());
sb.Append("<hr />");
sb.Append("<footer>");
sb.Append("<p>© @DateTime.Now.Year - Excellor Software</p>");
sb.Append("</footer>" + "</div>");
sb.Append("</div>");
Response.Write(sb.ToString());
sb.Clear();
sb = null;
Response.WriteFile("../../includes/footer.inc");
</body>
</html>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55049282%2fhow-to-reference-a-global-virtual-include-in-mvc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I actually got this to work. I HAD to work with these old virtual includes, I had no choice for the company.
I did this in the layout: I basically had to inject the includes with a Response.WriteFile to the place up the directory tree where the includes were located. These includes are used for ALL web sites in our company. Then I used a StringBuilder to build the content within the layout. I also had to put the @RenderBody statement within the Response object as well.
@using System.Text;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple."/>
<meta name="title" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple." />
<meta name="robots" content="index, follow" />
<meta name="keywords" content="software, training, Android, mobile, iOS, Apple, data, visualization" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link rel="icon" href="~/Content/favicon3.ico" type="image/x-icon" />
</head>
<body>
@
Response.Buffer = false;
Response.BufferOutput = false;
Response.WriteFile("../../includes/header.inc");
StringBuilder sb = new StringBuilder(4000);
sb.Append("<div class="container body-content">");
sb.Append(@RenderBody());
sb.Append("<hr />");
sb.Append("<footer>");
sb.Append("<p>© @DateTime.Now.Year - Excellor Software</p>");
sb.Append("</footer>" + "</div>");
sb.Append("</div>");
Response.Write(sb.ToString());
sb.Clear();
sb = null;
Response.WriteFile("../../includes/footer.inc");
</body>
</html>
add a comment |
I actually got this to work. I HAD to work with these old virtual includes, I had no choice for the company.
I did this in the layout: I basically had to inject the includes with a Response.WriteFile to the place up the directory tree where the includes were located. These includes are used for ALL web sites in our company. Then I used a StringBuilder to build the content within the layout. I also had to put the @RenderBody statement within the Response object as well.
@using System.Text;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple."/>
<meta name="title" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple." />
<meta name="robots" content="index, follow" />
<meta name="keywords" content="software, training, Android, mobile, iOS, Apple, data, visualization" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link rel="icon" href="~/Content/favicon3.ico" type="image/x-icon" />
</head>
<body>
@
Response.Buffer = false;
Response.BufferOutput = false;
Response.WriteFile("../../includes/header.inc");
StringBuilder sb = new StringBuilder(4000);
sb.Append("<div class="container body-content">");
sb.Append(@RenderBody());
sb.Append("<hr />");
sb.Append("<footer>");
sb.Append("<p>© @DateTime.Now.Year - Excellor Software</p>");
sb.Append("</footer>" + "</div>");
sb.Append("</div>");
Response.Write(sb.ToString());
sb.Clear();
sb = null;
Response.WriteFile("../../includes/footer.inc");
</body>
</html>
add a comment |
I actually got this to work. I HAD to work with these old virtual includes, I had no choice for the company.
I did this in the layout: I basically had to inject the includes with a Response.WriteFile to the place up the directory tree where the includes were located. These includes are used for ALL web sites in our company. Then I used a StringBuilder to build the content within the layout. I also had to put the @RenderBody statement within the Response object as well.
@using System.Text;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple."/>
<meta name="title" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple." />
<meta name="robots" content="index, follow" />
<meta name="keywords" content="software, training, Android, mobile, iOS, Apple, data, visualization" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link rel="icon" href="~/Content/favicon3.ico" type="image/x-icon" />
</head>
<body>
@
Response.Buffer = false;
Response.BufferOutput = false;
Response.WriteFile("../../includes/header.inc");
StringBuilder sb = new StringBuilder(4000);
sb.Append("<div class="container body-content">");
sb.Append(@RenderBody());
sb.Append("<hr />");
sb.Append("<footer>");
sb.Append("<p>© @DateTime.Now.Year - Excellor Software</p>");
sb.Append("</footer>" + "</div>");
sb.Append("</div>");
Response.Write(sb.ToString());
sb.Clear();
sb = null;
Response.WriteFile("../../includes/footer.inc");
</body>
</html>
I actually got this to work. I HAD to work with these old virtual includes, I had no choice for the company.
I did this in the layout: I basically had to inject the includes with a Response.WriteFile to the place up the directory tree where the includes were located. These includes are used for ALL web sites in our company. Then I used a StringBuilder to build the content within the layout. I also had to put the @RenderBody statement within the Response object as well.
@using System.Text;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple."/>
<meta name="title" content="Software that excels. Training that inspires. Build your company mobile presence on Android and Apple." />
<meta name="robots" content="index, follow" />
<meta name="keywords" content="software, training, Android, mobile, iOS, Apple, data, visualization" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link rel="icon" href="~/Content/favicon3.ico" type="image/x-icon" />
</head>
<body>
@
Response.Buffer = false;
Response.BufferOutput = false;
Response.WriteFile("../../includes/header.inc");
StringBuilder sb = new StringBuilder(4000);
sb.Append("<div class="container body-content">");
sb.Append(@RenderBody());
sb.Append("<hr />");
sb.Append("<footer>");
sb.Append("<p>© @DateTime.Now.Year - Excellor Software</p>");
sb.Append("</footer>" + "</div>");
sb.Append("</div>");
Response.Write(sb.ToString());
sb.Clear();
sb = null;
Response.WriteFile("../../includes/footer.inc");
</body>
</html>
answered Mar 9 at 2:09
Charles OwenCharles Owen
70367
70367
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55049282%2fhow-to-reference-a-global-virtual-include-in-mvc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Have you seen this post: stackoverflow.com/questions/5021763/…
– David Tansey
Mar 7 at 17:11
@DavidTansey: That's pretty old. Is it still the canonical way to do it?
– Robert Harvey♦
Mar 7 at 17:14
Ahhh, that could work as well. I didn't think you could reference .ascx files within a PartialView if you're using Razor as your view engine. See how I did it below. Yes, it looks like a kluge but actually works. I'll look at your solution as well. Actually that solution you posted wouldn't work for me because the includes have to be located in a central location well outside of the directory structure of the application. Since someone may change content in the include globally, if I had the content within the application, I wouldn't be picking up the changes.
– Charles Owen
Mar 9 at 2:12