By "add html widget razor code" do you mean to add razor code to Html Widget ? If this is your question - unfortunately it is not possible.
About your second question: If I understand you correctly you need to add Html Widget on Topic page ? If this is what you need you will have to add a new widget zone in the TopicDetails.cshtml view and also add the new widget zone to the SupportedWidgetZones.xml file in the Html Widgets plugin.