Related Links

Executing Html.TextBox in controller code

Dumb question, but I can't find the namespace where it's stored - in the view code I can execute Html.TextBox(<name>, <contents>, <html attribs>) and Html.DropDownList(<name>, <select list contents>, <html attribs>) but how do I execute these methods in
controller code?

In case you are wondering why on earth I want to do this, rather than using the TextBox object, I execute Html.TextBox(....).ToString() and create html code from these objects.

Cheers

MH

Please remember to mark replies as answers if you find them useful =8)

Re: Executing Html.TextBox in controller code

Thanks, that's what I needed. Actually, that's a lot more simple than typing the html code as I am creating DropDownLists and Checkbox objects with this too (the controller method is an AJAX called one that is returning html), and I needed to keep the returned
objects consistent with any generated on the view (esp WRT the way .net creates checkbox elements).

Please remember to mark replies as answers if you find them useful =8)

Re: Executing Html.TextBox in controller code

Actually, I'd avoid the whole construct. The point is to get the input tag string from the helper. If we were to write to Response.Output, it'll output directly to the response. What if the request is an Ajax (or more correctly, an AJAH) request? Wouldn't
that break the response format entirely? As such, it'd be better to throw than to write directly to the output from the controller.

"If I can see further than anyone else, it is only because I am standing on the shoulders of giants."blog: www.heartysoft.comtwitter: @ashic

Re: Executing Html.TextBox in controller code

Revisiting the topic Brad, TextWriter.Null does not pass in a null, it's a dummy textwriter that can be written to but not read from. As such, any helper writing to the textwriter will be able to write perfectly. Does any Html helper actually need to read
form the textwriter?

"If I can see further than anyone else, it is only because I am standing on the shoulders of giants."blog: www.heartysoft.comtwitter: @ashic

Re: Executing Html.TextBox in controller code

anyone figure this out? I'd like to be able to call an Html.TextBox from my custom HtmlHelper class so I can return groups of form fields together (like label tied to text box for example). Having to hardcode the html seems silly when the helpers already
exist.