HTML页面与MVC中的剃刀引擎布局视图集成

时间:2021-07-11 13:42:11

We are developing a web application in MVC4. The layout view name is layout.cshtml which is cshtml file (Razor engine) and we did several essential things (such as login div) in layout view. Recently a requirement has met that we need to integrate several static HTML page with this MVC4 web application. The problem that we face is,

我们正在开发MVC4中的Web应用程序。布局视图名称是layout.cshtml,它是cshtml文件(Razor引擎),我们在布局视图中做了几个基本的东西(比如登录div)。最近有一个要求,我们需要将几个静态HTML页面与这个MVC4 Web应用程序集成。我们面临的问题是,

  • It is compulsory that users who view the static HTML also need to access to this login div. So the master pages of all those static HTML must be layout.cshtml.
  • 查看静态HTML的用户也必须访问此登录div。因此,所有这些静态HTML的母版页必须是layout.cshtml。

  • Since we code several other views in this application which depends on this layout, we can't change the layout from CSHTML to HTML.
  • 由于我们在此应用程序中编写了几个依赖于此布局的其他视图,因此我们无法将布局从CSHTML更改为HTML。

Considering these scenario, how can we integrate those HTML pages having master page as layout.cshtml with this web application. Thanks in advance.

考虑到这些场景,我们如何将具有母版页作为layout.cshtml的HTML页面与此Web应用程序集成。提前致谢。

1 个解决方案

#1


You can embed partial view partial view demo with the Html (only the html into body), it is one clean way to achieve what you want if I did well understood your problem.

您可以使用Html嵌入部分视图局部视图演示(仅将html嵌入到正文中),如果我很好地理解了您的问题,它是实现您想要的一种干净方式。

You just ave to put the static html into "_static.cshtml" without razor if you want and then include it by using

如果你愿意,你只需要将静态html放入“_static.cshtml”而不用剃刀,然后使用它来包含它

@Html.Partial("_static")

I also recommand you to make partialview with the login form too, your layout.cshtml could be more clear for editing

我还建议您使用登录表单进行部分查看,您的layout.cshtml可以更清晰地进行编辑

If you want to handle lots of partial, then you can use only one controller and use one string.. something like this:

如果你想处理很多部分,那么你只能使用一个控制器并使用一个字符串..这样的事情:

List of available pages

可用页面列表

<ul>
    <li>
        @Html.ActionLink("page1", "GetStatic", "Home", new { name = "page1" }, null)
    </li>
    <li>
        @Html.ActionLink("page2", "GetStatic", "Home", new { name = "page2" }, null)
    </li>
</ul>

Controller hitten by clicking on list items:

通过单击列表项来控制控制器:

public ActionResult GetStatic(string name)
        {
            if(name .IsNotNull())
            {
                return View(model:name);
            }
            return RedirectToAction("Index");
        }

GetStatic.cshtml:

@model String

@Html.partial("@Model")

#1


You can embed partial view partial view demo with the Html (only the html into body), it is one clean way to achieve what you want if I did well understood your problem.

您可以使用Html嵌入部分视图局部视图演示(仅将html嵌入到正文中),如果我很好地理解了您的问题,它是实现您想要的一种干净方式。

You just ave to put the static html into "_static.cshtml" without razor if you want and then include it by using

如果你愿意,你只需要将静态html放入“_static.cshtml”而不用剃刀,然后使用它来包含它

@Html.Partial("_static")

I also recommand you to make partialview with the login form too, your layout.cshtml could be more clear for editing

我还建议您使用登录表单进行部分查看,您的layout.cshtml可以更清晰地进行编辑

If you want to handle lots of partial, then you can use only one controller and use one string.. something like this:

如果你想处理很多部分,那么你只能使用一个控制器并使用一个字符串..这样的事情:

List of available pages

可用页面列表

<ul>
    <li>
        @Html.ActionLink("page1", "GetStatic", "Home", new { name = "page1" }, null)
    </li>
    <li>
        @Html.ActionLink("page2", "GetStatic", "Home", new { name = "page2" }, null)
    </li>
</ul>

Controller hitten by clicking on list items:

通过单击列表项来控制控制器:

public ActionResult GetStatic(string name)
        {
            if(name .IsNotNull())
            {
                return View(model:name);
            }
            return RedirectToAction("Index");
        }

GetStatic.cshtml:

@model String

@Html.partial("@Model")