ajax-C#

 $(document).ready(function(){
    $("#month").change(function () {
        var yearSelect = $("#year").find("option:selected").val();
        var monthSelect = $("#month").find("option:selected").val();
        var jsonFormat = "{year:" + yearSelect + ",month:" + monthSelect + "}";
        $.ajaxWebService("GetInfo", jsonFormat, function (data) {
        });
    });
    });

    $.ajaxWebService = function (url, dataparam, datasuccess) {
        $.ajax({
            type: "POST",
            dataType: "json",
            contentType: "application/json",
            url: url,
            data: dataparam,
            success: datasuccess,
            error: function (a, b, c) { }
        });
    }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NXT.Areas.Anm.Controllers
{
    public class MonthlyReportController : Controller
    {
        //
        // GET: /Anm/MonthlyReport/

        public ActionResult Index()
        {
            string year = Request["year"];
            string month = Request["month"];
            return View();
        }

        [HttpPost]
        public JsonResult GetInfo(string year,string month)
        {
            //***
            var data = new
            {
                id = 1,
                text = "sdfsdfsdfsdf"
            };
            return Json(data, JsonRequestBehavior.AllowGet);
        }
    }
}
原文地址:https://www.cnblogs.com/hellowzd/p/4468354.html