Using HtmlHelper in a Controller

后端 未结 7 1456
悲哀的现实
悲哀的现实 2020-11-27 04:34

Is it possible to use HtmlHelper in a controller, for-example to get the TextBox(...) method? not that I can\'t write the html that it generates myself, but I just want to u

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 05:16

    The HtmlHelper is part of the View mechanism by design and should be considered separate to the Controller and Model parts of MVC. I am not sure why you would want to generate controls inside the controller as it's role is to deliver the Data to the view for rendering.

    I am not saying that you cannot achieve it, but for good design it would be better.

    Can you explain what you are trying to achieve and then we could look at doing it in an "MVC way"?

提交回复
热议问题