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

后端 未结 2 1248
暖寄归人
暖寄归人 2021-01-04 14:06

With the Razor view engine in MVC3,

Is it possible to render a legacy ascx?


I was expecting to be able to do something lik

相关标签:
2条回答
  • 2021-01-04 14:43

    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 讨论(0)
  • 2021-01-04 14:48

    Yes. Try this instead:

    @Html.Partial("Footer")
    

    or

    @{ Html.RenderPartial("Footer"); }
    
    0 讨论(0)
提交回复
热议问题