简体   繁体   English

HTML 页面的实时预览

[英]Live Preview of HTML Page

I have found some related answers, but I'm not sure they will work for me.我找到了一些相关的答案,但我不确定它们是否适合我。

Essentially I am working on a webpage which generates an online menu for the user.本质上,我正在开发一个为用户生成在线菜单的网页。 The idea is to have a page where the user can select the options for this page (background, font, etc.) and see a live preview of their choices.这个想法是有一个页面,用户可以在其中 select 该页面的选项(背景、字体等)并查看他们选择的实时预览。

The inputs will of course be in a form with selects and inputs and color pickers.输入当然是带有选择和输入以及颜色选择器的形式。 The problem is I don't know how to do the live preview.问题是我不知道如何进行实时预览。

I am doing this in .net core 5 mvc so it may be that there will have to be a button to update the page (I am not writing the code for the editable page) so the "live" part isn't as important as the preview part.我在 .net 核心 5 mvc 中执行此操作,因此可能必须有一个按钮来更新页面(我没有为可编辑页面编写代码),因此“实时”部分不如预览部分。

Importantly, say the preview is only 280px wide (galaxy fold) I want the page being previewed to still look it would on a screen say 1920px wide.重要的是,假设预览只有 280 像素宽(星系折叠),我希望被预览的页面在屏幕上仍然看起来像 1920 像素宽。

You can achieve this in the following way您可以通过以下方式实现此目的

  1. Create a view model from user selected style options从用户选择的样式选项创建view model
  2. Pass the view model to the view将视图 model 传递给视图
  3. Then you need to generate html from razor using razor engine然后你需要使用 razor 引擎从 razor 生成 html
  4. That html you can show with Html.Raw() in a div (with small height & width) in your view您可以使用Html.Raw()在您的视图中显示 html

or或者

you can also do this by opening the view inside an iframe by passing the url and user selected options.您也可以通过传递 url 和用户选择的选项打开 iframe 内部的视图来执行此操作。

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

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