MVC3 Razor: Is it Possible to Render a Legacy ASCX?

随声附和 提交于 2019-11-30 03:06:47

问题


With the Razor view engine in MVC3,

Is it possible to render a legacy ascx?


I was expecting to be able to do something like:

@Html.RenderPartial("Footer.ascx")

回答1:


Yes. Try this instead:

@Html.Partial("Footer")

or

@{ Html.RenderPartial("Footer"); }



回答2:


Just wanted to add that I haven't seen a lot of people posting this solution:

Html.RenderAction("Footer", "Home");

This is better practise if you are using MVC, because you can specify any data you need in the controller instead of trying to manage it in a free-floating partial view. Very beneficial if you use a BaseController class to initialize all your calls.

public class HomeController : Controller {
    // ...

    [ChildActionOnly]
    public PartialViewResult Footer() {
         // do work
        return PartialView();
    }

    // ...
}


来源:https://stackoverflow.com/questions/6538869/mvc3-razor-is-it-possible-to-render-a-legacy-ascx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!