Some examples I found that apparently worked with older versions of mvc suggest that there was a length parameter of sorts:
<%=Html.TextBox("test", 50)%>
But that may have been mistakenly setting the value.
How do this work in the current release? Passing in the style doesn't appear to have any effect.
There are two ways in MVC to create custom Html helpers as below. We can create our own HTML helper by writing extension method for HTML helper class. These helpers are available to Helper property of class and you can use then just like inbuilt helpers. Add new class in MVC application and give it meaningful name.
In MVC, HTML Helper can be considered as a method that returns you a string. This string can describe the specific type of detail of your requirement. Example: We can utilize the HTML Helpers to perform standard HTML tags, for example HTML<input>, and any <img> tags.
Template helper is introduced in MVC-2, and it is classified into two categories. @Html. DisplayForModel() :- This Display template helper is used with strongly typed views. It goes through the every property in the model for displaying object.
The Strongly-Typed HTML helper (i.e., NumericTextBox) takes lambda as a parameter that tells the helper, which element of the model to be used in the typed view. The Strongly typed views are used for rendering specific types of model objects, instead of using the general ViewData structure.
The original answer is no longer working as written:
<%=Html.TextBox("test", new { style="width:50px" })%>
will get you a text box with "{ style="width:50px" }" as its text content.
To adjust this for the current release of MVC 1.0, use the following script (note the addition of the second parameter - I have mine starting as blank, adjust accordingly based on your needs):
<%=Html.TextBox("test", "", new { style="width:50px" })%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With