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).In a javascript dialog page i have one 'ok' button.. when i click the button i want to store the value entered in the textbox.I want to save the content using Ajax.
Please see my 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
where SearchtextValue.OptionName == str
select SearchtextValue.OptionName).Single();
if (value == null)
{
return 1;
}
return 0;
}
}
When i run this code i am getting script error like "Object doesn't support this property or method".Please advice