Can I set a value in @ html.label using jquery in asp.net mvc4?

i has @Html.Label("", new { id="txtStatus1" })

where the value of txtstatus1 is obtained using jquery as $('#txtStatus1').val(TicketStatus);

but im cannot set this value for label.

+4
source share
2 answers

This statement does not output anything since you did not specify a value for:

@Html.Label("", new { id="txtStatus1" })

If you change it to give it a value of ie

@Html.Label("a", new { id="txtStatus1" })

He outputs this:

<label for="a" id="txtStatus1">a</label>

Sridhar R is correct, you can use text to set it like this:

$('#txtStatus1').text('this')

http://jsfiddle.net/bk8KZ/

You may need to add quotation marks and output around the argument if it is being sent from your model i.e.

$('#txtStatus1').val('@Model.TicketStatus');

What is TicketStatus?

+7
source

.text() .html()

html

var txt = $('#lbltxt').html();

html

$('#lbltxt').html("your value");

asp.net, , .

var txt = $('#<%=lbltxt.ClientID%>').html();

var txt = $("[id$='lbltxt']").html()

Asp.net

$('#<%= lbltxt.ClientID%>').html('Your Value')

$("[id$=' lbltxt']").html('Your Value')
+3

All Articles