I need this displayfor to update its value from using jquery.
I tried .val() and .text() but neither worked, is there a special way to do this for Displays, I need it to be and stay as a Display.
Also can the style not be set for Displays? I never could get that to work, it works for TextboxFor.
Thanks for any tips.
Estimated Time: @Html.DisplayFor(model => model.EstimatedTime, new { @class = "TitleEstTimeClass", @style = "color: green" })
$(".TitleEstTimeClass").val(result[1]);
DisplayForgenerates a label HTML tag<label id="myId" class="myClass">Some Text</label>. (INCORRECT)EDIT
I was wrong and thought you were using the
LabelForhelper. TheDisplayForhelper outputs no HTML markup (like a label or span tag). If you want this to work with theDisplayForhelper, you will need to wrap theDisplayFortag with a<span>or something similar like below:Given this, try using the
.html()JQuery property like below – it really is no different than updating the text in div or span:Also, be sure that your JQuery call is in the appropriate
<script></script>tags and that the function that you are calling is actually being fired. I am not sure if the above code is straight from your project or just snippets, but as written above, nothing will happen.