开发者

Html - Helper in Custom ModelBinder

开发者 https://www.devze.com 2023-02-12 09:17 出处:网络
Is there a way to get an instance of the Html-Helper within a custom Model-Binder? E.g.: public class TranslationModelBinder : DefaultModelBinder

Is there a way to get an instance of the Html-Helper within a custom Model-Binder?

E.g.:

public class TranslationModelBinder : DefaultModelBinder
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingCo开发者_运维问答ntext)
    {
       // HtmlHelper helper = new HtmlHelper(?,?);
       object model = base.BindModel(controllerContext, bindingContext);
    }
}

How can I get the two needed arguments?

Thx for any tipps! sl3dg3


Even if you could, it would be wrong.

HtmlHelper is a tool for the view where it renders the Model while the binder does the opposite.


The model binder runs much before the view executes so that you don't have a ViewContext yet which allows you to obtain an HtmlHelper. You could probably fake this context but that is not something I would recommend you doing. You could have an UrlHelper though.

0

精彩评论

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