Issue while store the javascript textbox value into DB using ajax code in MVC2 -


i may missing obvious here, how rewrite code!

i trying here store value entered in textbox(textbox showed in javascript dialog page).in javascript dialog page have 1 'ok' button.. when click button want store value entered in textbox.i want save content using ajax.

please see sample code view page:

<script language="javascript" type="text/javascript">     $(function () {         $('.button').live('click', function () {             $('.text_dialog').dialog('open');         });          $('.text_dialog').dialog({             autoopen: false,             buttons: {                 'ok': function () {                     var textvalue = $(':txtvalue').val();                     $.ajax({                         url: '/home/about',                         type: 'post',                         data: { str: textvalue },                         success: function (result) {                             alert(result.val);                         }                     });                 },             }         });     });  </script>        <input type="button" value="add value" class="button" />      <div class="text_dialog" title="basic modal dialog">           textvalue: <input type="text" class="txtvalue" /> </div> 

control page:

[httppost]     public actionresult about(string str)     {         validateclass objam = new validateclass();         int value = objam.validatetextvalue(str);         return json(new { val = value });     } 

model page:

 public class validateclass     {         dataclasses1datacontext dbobj = new dataclasses1datacontext();         public int validatetextvalue(string str)         {             string value = (from searchtextvalue in dbobj.options                                 searchtextvalue.optionname == str                                 select searchtextvalue.optionname).single();             if (value == null)             {                 return 1;             }             return 0;          }     } 

when run code getting script error "object doesn't support property or method".please advice

change data: { str: textvalue } data: "{ 'str' :'" + textvalue +"' }"

if confused on escaping quotes properly, try this.

$(function() {     $('.button').live('click', function() {         $('.text_dialog').dialog('open');     });      $('.text_dialog').dialog({         autoopen: false,         buttons: {             'ok': function() {                 var dto = "{ 'str' :'" + $('.txtvalue').val() +"' }";                 $.ajax({                     url: '/home/about',                     type: 'post',                     data: dto,                     success: function(result) {                         alert(result.val);                     }                 });             },         }     }); }); 

please note have changed :txtvalue .txtvalue correct selector.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -