开发者

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

开发者 https://www.devze.com 2023-03-16 07:43 出处:网络
With the Razor view engine in MVC3, Is it possible to render a legacy ascx? I was expecting to开发者_JAVA技巧 be able to do something like:

With the Razor view engine in MVC3,

Is it possible to render a legacy ascx?


I was expecting to开发者_JAVA技巧 be able to do something like:

@Html.RenderPartial("Footer.ascx")


Yes. Try this instead:

@Html.Partial("Footer")

or

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


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();
    }

    // ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消