0

Possible Duplicate:
Watermark for Textbox in MVC3

Im switching my HTML code from basic html to use html helpers and Html.TextBoxFor...

This is my old code

<input type="text" disabled="disabled" value="Phone" name="Phone" id="cust-cellphone" class="tonedDown" />

And this is the new version

@Html.TextBoxFor(x => x.Customer.Phone_Personal, new { @class = "text-adr-fld tonedDown", @value = "Phone", @disabled = "disabled" })

Everything is working fine, except that the Value property is gone. What I mean is that it's not showing as a default predefined value inside the textbox. I read that you can use Placeholder, but it doesnt seem to work with IE9 (which is a requirement from my client).

So the question is, how do I add input Value property to the TextboxFor method that works with IE9?

Edit: There might be a possible workaround somehow. My original purpose with this is to display a "placeholder like value", ie a default value which shows what the user is supposed to type in the textbox. E.g. the textbox that handles phonenumber should display "Phone", until the user clicks and enters a value.

Does anyone know another way of doing this (except "placeholder" and "value")?

Community
  • 1
  • 1
Martin
  • 1,916
  • 2
  • 25
  • 37
  • there are plenty of work around using jquery for this, check [this question and its answers](http://stackoverflow.com/q/6445274/1182982) on SO. also check [this](http://stackoverflow.com/q/5120257/1182982) out – Yasser Shaikh Oct 10 '12 at 09:54
  • Use Value instead value. – Viku Mar 12 '15 at 11:23

2 Answers2

1

u can set the default value to your model, and then your piece of code will work, else you can try using

    @Html.TextBox("Phone_Personal", "Phone", new { @class = "text-adr-fld tonedDown", @disabled = "disabled" }).

If u want to use TextBoxFor, then using

   $(document).ready(function(){
      $("#Phone_Personal").val("Phone"); // replace Phone_Personal with the ID of the textbox
   });
Developer
  • 759
  • 2
  • 9
  • 24
0

I think you don't pass the model to View method :

 return View(model);

Or,the model is null.

Yasser Sinjab
  • 578
  • 6
  • 19
  • Im passing a class in the return statment: return View(order); and then Im specifying the model in the top of the cshtml file: @model Mylibrary.Web.Order – Martin Oct 10 '12 at 10:46
  • Do I need a specific Model class that I pass to View? Or does my way of passing a class work in the same way? – Martin Oct 10 '12 at 10:48
  • Thats good,but set a breakpoint at the returning view statement ,and check if your model (Order) that you are passing to "View(order)" is null or not. – Yasser Sinjab Oct 10 '12 at 10:58
  • The Order object isnt null. But all the field values are (ofc, the user hasnt inputed them yet)... – Martin Oct 10 '12 at 11:23
  • hmmm...try setting those properties to default values,for example:if the property is string,set it as String.Empty. – Yasser Sinjab Oct 10 '12 at 11:31
  • There is an attribute called "[DefaultValue()]" ,try to write it above "Order"'s properties. check this link plz:http://stackoverflow.com/questions/6779881/annotating-properties-on-a-model-with-default-values and http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultvalueattribute.aspx – Yasser Sinjab Oct 10 '12 at 11:34