Issue While Store The Javascript Textbox Value Into Db Using Ajax Code In Mvc2
I may be missing something obvious here, but how could I rewrite this code! i am trying here to store the value entered in the textbox(Textbox was showed in javascript dialog page)
Solution 1:
Change to data: { str: textValue }
data: "{ 'str' :'" + textValue +"' }"
If you are confused on escaping the quotes properly, try this.
$(function() {
$('.button').live('click', function() {
$('.Text_dialog').dialog('open');
});
$('.Text_dialog').dialog({
autoOpen: false,
buttons: {
'Ok': function() {
varDTO = "{ 'str' :'" + $('.txtValue').val() +"' }";
$.ajax({
url: '/Home/About',
type: 'POST',
data: DTO,
success: function(result) {
alert(result.val);
}
});
},
}
});
});
Please note that I have changed the to :txtValue
.txtValue
as it is the correct selector.
Solution 2:
can you try changing
<inputtype="text"class="txtValue" />
to
<inputtype="text"class="txtValue"id="txtValue" />
and
var textValue = $(':txtValue').val();
to
var textValue = $('#txtValue').val();
I've never used :
selector... but I think it will return you a collection and you should use index [0]
or, why don't you use class selector .
?
Edit: as I see you cannot use :
in this case
also you can add dataType: "json"
,into your Ajax request, and change your method return type from
public ActionResult About(string str)
to
public JsonResult About(string str)
EDIT 2:
have you included the library where dialog() function is? after including the jquery library?
Post a Comment for "Issue While Store The Javascript Textbox Value Into Db Using Ajax Code In Mvc2"