In ASP.NET, I would have an ascx control, and it would call Scriptmanager.RegisterClientScriptBlock in its own Load() method.
I’d have a block of javascript like
var myObject = CreateNewMyObject(param, param, param...);
which would be a method in my javascript library to go off and create the control on the page.
However in MVC I have never done this before so I am unsure what to do.
I can call a method such as @(this.Html.RenderMyObject(param, param)) which will return fully rendered html, but I want to do it as above – the javascript function renders the html.
Should I return var myObject = CreateNewMyObject(param, param, param...); from a method like this, or is there a much nicer way?
I think the idea with MVC, especially with Razor, is that you use Javascript as you want to. If I understand your question correctly, you could call your javascript function directly in the onLoad javascript function on the Razor page.
However, if the only thing your javascript does is paint up a control, I would recommend creating a @HTML Helper like you mentioned in your question.