Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to set value in @html.label using jquery in asp.net mvc4?

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

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

but im not able to set this value to label .

like image 273
Joseph Avatar asked Dec 09 '13 11:12

Joseph


2 Answers

This statement does not output anything as you have not specified a for value:

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

If you change it to give it a value i.e.

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

It 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 might need to add quotes and output around the argument if it is comming from your model i.e.

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

What is TicketStatus exactly?

like image 135
hutchonoid Avatar answered Sep 21 '22 18:09

hutchonoid


Try this

Use .text() or .html()

Get html label value

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

Set html label value

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

To get asp.net label value we need to write the code like as shown below

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

or

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

Set Asp.net label Value

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

Or

$("[id$=' lbltxt']").html('Your Value')
like image 24
Sridhar R Avatar answered Sep 20 '22 18:09

Sridhar R