Hi,
I am following Mike Brind's example to add records to a webgrid using an AJAX form post.
http://www.mikesdotnetting.com/Article/155/WebMatrix-And-jQuery-Forms
The only difference is that I am using dropdown box on the main form to display a filtered dataset in the webgrid.
When I add a record using the popup dialogue box and refresh my webgrid, I lose the filter on my webgrid and see all records.
I want to maintian my filtered webgrid after the webgrid is refreshed
Below is the RAZOR code and the jQuery/AJAX code.
Thanks
Geoff
@{vardb=Database.Open("StarterSite");varmodules=db.Query("SELECT ModuleID, ModuleName FROM Modules WHERE Active=1 And ModuleLevelType = N'Lower Level Driver' ORDER BY Path");varsql="SELECT QuestionMasterList.QuestionID, QuestionMasterList.ModuleID, QuestionMasterList.QuestionCode, QuestionMasterList.Question, AnswerType.AnswerType";sql+=" FROM QuestionMasterList LEFT JOIN AnswerType ON QuestionMasterList.AnswerTypeID = AnswerType.AnswerTypeID";varanswerTypes=db.Query("Select * FROM AnswerType");varbDisplayHeader=false;if(IsPost){if(Request["module"].IsInt()){sql+=" WHERE ModuleID = @0";}}varquestions=db.Query(sql,Request["module"]);vargrid=newWebGrid(questions,canPage:false,ajaxUpdateContainerId:"grid");}
$('#dialog-form-add').dialog({ autoOpen:false, modal:true, height:575, width:575, beforeClose:function(){ validator.resetForm();}, buttons:{'Save':function(){ bValid =$("#add-book-form").valid();if(bValid){$.ajax({ type:"POST", url:$("#add-book-form").attr('action'), data:$("#add-book-form").serialize(), dataType:"text/plain", success:function(response){$('#dialog-form-add').dialog('close');$("#grid").load('/MasterQuestions #grid',function(){$('tbody > tr:last') .effect("highlight",{},2000);});}, error:function(response){ alert(response);$('#dialog-form').dialog('close');}});}}, Cancel:function(){$('#dialog-form-add').dialog('close');}}});