jquery - AJAX and MVC (C#) -


I have never used AJAX and I do not quite know much in JS.

I have a page () that has the following breakdown:

  1. Navigation (first, previous, 1, 2, 3 next, last) - Full post back
  2. item drop down per page - I want to make it AJAX
  3. left column - filter - I want to do AJAX it
  4. Product display area - 1, 2 and Amp; 3 above

I am starting with item # 2 and trying to figure out how to change item 4, depending on the exchange event for drop down. Where am I at a loss as to or how to start, should it be AJAX? JQuery? A combination of both? And remember - this is in an MVC based app.

TIA

The answer is definitely "yes" for your question.

I just got one in front of me, so I will try to take it out.

In the past, the action of a controller that gives a JasonResult (instead of the actionrzult) except its return type, it is like any other action, so that you can send parameters, etc. The only thing that really is different is that you are returning a JasonSentelt () object, setting up your data property and other properties may be required. Something looks like this (very pseudo-coded ...):

  Public JSOUSELTT GetList {} {var results = dataRepository.GetById (parentId); Return new Jason Resolve () {Data = Results Toure (); }; }  

Now, in your opinion, create such a visible script. Note that this is the syntax of jQuery, so if you are not familiar with it then it may look a little unusual.

  & lt; Script language = "javascript" type = "text / javascript" & gt; // When the document is ready, start firing our AJAX $ (document) .ready (function () {// bind a function in the "change" event of our drop-down list $ ("# dropDownId") "Change", function (e) {updateList ();})}} Retrieve data = function (path, parent ID, FNHindleCollback) {// use getJSON method to call your JSRSaltAction $$ .getJSON (Path, {parentId: parentId}, function (data) {fnHandleCallback (data);});}; // Path parameter Our JSON Controller Function Update List () {Recover Data ("/ Controller / Getlist", $ ("# DropdownId"). Val (), HandleResponse;} Function Handling Response (Data) {// OK Now, we have JSON data, we need to do something with it. I'm adding it to another dropdown. $ ("#otherDropDownId") .remove (); (Data in d) {var item = data [D]; $ ("#otherDropDownId") Attachments ("& lt; Option value = \" "+ item.Value +" \ "& gt;" + Item. Text + "& lt; / option & gt;");}} & lt; / Script & gt; & Lt;% = Html.DropDownList ("Dropdown WnId", New Selection List (New List & amp; lt; SelectListItem & gt; ()))% & gt; & Lt;% = Html.DropDownList ("Other Drawdown ID", New Selection List (New List & amp; lt; SelectListItem & gt; ()))% & gt;  

This is very far from the top of my head, so let me know that something needs to be clearer or correct.

Edit

As stated in my comment, so that you can "AJAXify" your page, Do not want to push everything.

  Public JsonResult GetPagedData (int page, int item perpage, string [] filter) {var result = data repository. GetPagedItems (PageEd, Item PerPage, Filters); Return new Jason Resolve () {Data = Results Toure (); }; }  

JS changes:

  var retrieved data = function (path, page number, pageisms, filter, FNHoldbackback) {// getJSON method used To call us, call JsonResult $ .getJSON (Path, {Page: Page Number, ItemPrint, Filter: Filter}, Function (Data) {fnHandleCallback (Data);}); }; // path parameter is updated in our JSON controller action function (list) (retrieve data ("/ controller / GetPagedData", $ ("# page number"). Val (), $ ("# dropDownId"). Val () Null, handleResponse);}  

I have deliberately detected both page numbers and filters - they will essentially follow the same principles.

Finally, when You will add data to your product grid instead of any other drop-down.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -