Friday, June 29, 2012

How to make simple AJAX call on HTML input button and get JSon result in MVC 3

Here is the simplest code to make Ajax calls to MCV on an HTML button click using javascript.


JS Code:
funtion btnClick(){
var URL = "/myController/ myAction ?userID=" + Parameter1 + "&ReceiptNo=" + Parameter2 ;
                    $.get(URL, function (data) {
                        ShowResult(data.ProcessResult);
                         }

HTML Code (View):

  <input name="ClickedButton" type="button" id="btnclickme" value="Check Result"
                    onclick="btnClick()" class="commonbtn FR" />

C# Code (Controller):
public ActionResult myAction(string Parameter1,string Parameter2 )
{
    int ProcessResult = 1;

    return Json(new { ProcessResult }, JsonRequestBehavior.AllowGet);

}

No comments:

Post a Comment