Custom controls with ASP.NET MVC Razor

后端 未结 5 1717
日久生厌
日久生厌 2020-12-09 09:38

How can I use custom controls with ASPNET.MVC Razor?

I want to use a custom control on a Razor view. for instance:

@Model         


        
5条回答
  •  自闭症患者
    2020-12-09 10:18

    I had the same demand. Wanted to use custom webcontrol from Razor/MVC page. One should not do that with controls, that is handling postback. You don't have the eventcycle to support that, but if your only demand is to use a 'rendering control', you could instantiate it in razor, and control where the rendering takes place:

    @{
      var myControl = new mycontrols.something();
      myControl.myattribute = Model.MyVar;
      mycontrol.RenderControl(new HtmlTextWriter(this.Output));
    }
    

提交回复
热议问题