简体   繁体   English

在现有的 ASP.NET MVC 页面中嵌入另一个 html 页面

[英]Embed another html page in an existing ASP.NET MVC page

I've got over a decade of C# desktop application development under my belt but I'm new to ASP.NET MVC and my terminology may not be correct so i'll apologize ahead of time.我有十多年的 C# 桌面应用程序开发经验,但我是 ASP.NET MVC 的新手,我的术语可能不正确,所以我会提前道歉。

I've been working on an ASP.NET MVC 4 site that has jQuery 1.4 and bootstrap 3 as well as a lot of CSS customization.我一直在一个 ASP.NET MVC 4 站点上工作,该站点具有 jQuery 1.4 和 bootstrap 3 以及许多 CSS 自定义。 I've been trying to implement a feature and I've been able to do it separately with bootstrap 4 but when I copy the code over and render it in a Partial view, it turns out bad .我一直在尝试实现一个功能,我已经能够使用 bootstrap 4 单独完成它,但是当我复制代码并在 Partial 视图中呈现它时,结果是bad

I've spent a lot of time trying to figure out why it's displaying so poorly and I've realized that between the bootstrap 3 and 4 incompatibilities and all of the CSS customization the site has, it's almost infeasible to use this approach.我花了很多时间试图弄清楚为什么它的显示如此糟糕,并且我意识到在引导程序 3 和 4 不兼容以及站点具有的所有 CSS 自定义之间,使用这种方法几乎是不可行的。

Then I thought that I could just make all of my style changes inline but that doesn't make things very maintainable and is apparently frowned upon.然后我想我可以让我的所有style更改都内联,但这不会使事情非常易于维护并且显然不受欢迎。

With that being said, I've seen a number of posts about the usage of IFrame and it looks appealing but I have concerns.话虽如此,我已经看到许多关于 IFrame 使用的帖子,它看起来很吸引人,但我有顾虑。

  1. Will I be able to pass objects from the main cshtml page into the IFrame?我可以将对象从主cshtml页面传递到 IFrame 中吗?
  2. Will I be able to use different jQuery/bootstrap/CSS in the IFrame?我可以在 IFrame 中使用不同的 jQuery/bootstrap/CSS 吗?
  3. Are there any other options out there?还有其他选择吗?
  1. No. As it is a security concern, it is not possible.不可以。因为这是一个安全问题,所以不可能。
  2. Yes.是的。 The Iframe is rendered independently. Iframe 是独立呈现的。
  3. I think of two suggestions, no solution is easy and needs a lot of recoding:我想到了两个建议,没有一个解决方案是简单的,需要大量重新编码:
  • downgrade your partial view to bootstrap 3 : An obvious option that you are not looking for.将您的部分视图降级到 bootstrap 3 :您没有寻找的明显选项。
  • recompile bs4 with custom class names : Your problem is with the class names that have the same name but act different in bs3 and bs4.使用自定义类名重新编译 bs4 :您的问题在于具有相同名称但在 bs3 和 bs4 中行为不同的类名。 So, you can rename those class names in the source code of bs4 then compile and use them.因此,您可以在 bs4 的源代码中重命名这些类名,然后编译并使用它们。 for example: rename row class to bs4-row .例如:将row类重命名为bs4-row As you won't need all the bs4 library to style your code, you only need to rename and compile the files you need, like: _grid.scss.因为你不需要所有的 bs4 库来设计你的代码,你只需要重命名和编译你需要的文件,比如:_grid.scss。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM