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]);
DisplayFor
generates a label HTML tag <label id="myId" class="myClass">Some Text</label>
. (INCORRECT)
EDIT
I was wrong and thought you were using the LabelFor
helper. The DisplayFor
helper outputs no HTML markup (like a label or span tag). If you want this to work with the DisplayFor
helper, you will need to wrap the DisplayFor
tag with a <span>
or something similar like below:
<span class="TitleEstTimeClass" style="color: green">
@Html.DisplayFor(model => model.EstimatedTime)
</span>
Given this, try using the .html()
JQuery property like below - it really is no different than updating the text in div or span:
$(".TitleEstTimeClass").html(result[1]);
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.
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