Note that there are some explanatory texts on larger screens.

plurals
  1. POPossible to have empty values with Html For Helpers such as Html.TextBoxFor()?
    text
    copied!<p>Is it possible to have to make a html for helper in asp.net mvc 2.0 have a default value of "empty string"</p> <p>Like if I do this </p> <pre><code>Html.TextBoxFor( u =&gt; u.ProductName) </code></pre> <p>would render to</p> <pre><code>&lt;input id ="ProductName" name="ProdcutName" type="text" value="Jim" /&gt; </code></pre> <p>Now I don't want the textbox to display jim. I want it to display nothing.</p> <pre><code>&lt;input id ="ProductName" name="ProdcutName" type="text" value="" /&gt; </code></pre> <p>I tried to do this</p> <pre><code> Html.TextBoxFor( u =&gt; u.ProductName, new { @value = " "}) </code></pre> <p>but that seems to do nothing. So how can I do this. I hope you can do something like this otherwise I think these new helpers have a great flaw since now I need to use like javascript to remove them since I hardly ever want a default value in the textbox especially when I have a label right beside the textbox saying what it is.</p> <p><strong>Edit</strong></p> <p>I found that if I want to set it to a null string I have to do that in the viewmodel. What is fine but still one problem is left. In my example ProductName is a string type. But if it was say a int then it would show a default value to 0 which is something I don't want.</p> <p>So you can of course set a int to a empty string. So to get it to a empty string you need to change that type to a string what kinda sucks.</p> <p>Any one know away around this?</p> <p><strong>Edit 2</strong></p> <p>Also the radio button for helper does not seem to generate a "id". How do you set one?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload