开发者

MVC ASP.Net making htmlhelpers from within controllers

If I don't know what htmlhelper I want to use during design time.., Then is it appropiate to try to new up an htmlhelper from within the controller once I understand which model I will be using? So can I make from a controller an htmlhelper and add it to a view later that was not marked up to use the model开发者_Python百科? Like a data driven application? If so is there an example of doing so?


No.

HtmlHelper are extension methods of the MVC.ViewPage and MVC.ViewPage. They cannot be changed inside of a controller.

What you could do is pass a boolean, string, or whatever into your Views and then change the helper based on that.

<% if( Model.IsSomething ) { %>
      <%= Html.MyMagicMethod() %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜