MVC jQuery的阿贾克斯后返回null [英] Mvc Jquery Ajax Post returns null

查看:156
本文介绍了MVC jQuery的阿贾克斯后返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试后2 parameteres ... 这是阿贾克斯code

I have been trying to post two parameteres... This is the ajax code

function Kaydet() {
        var params = {};
        var Kiralayan = $("#RentForm").serialize();            
        params.kisi = Kiralayan ;
        params.aracid = P.AracID;           
        console.log(params);

        $.ajax({
            type: "POST",
            url: '@Url.Action("Save","AracKirala")',
            data: params,
            dataType: "text",
            success: function (response) {
                if (response != "OK") {
                    alert("Kayıt yapılamadı.");
                }
                else {
                    document.getElementById("RentForm").reset();
                    alert("Kayıt başarıyla gerçekleştirildi.");
                    $("#myModal").modal('hide');
                    Ara();
                }

            }
        });

方法

public ActionResult Save(Kiralayan kisi = null, int aracid = 0)
    {

问题是AJAX帖aracidcorretly但kisi变成空当方法触发时... 我试着不张贴aracid与kisi,让阿贾克斯贴好一个参数kisi,但不工作在一起...

the problem is ajax posts "aracid" corretly but "kisi" turns null when the method is trigged... I tried not to post "aracid" with "kisi" so ajax posted well for one parameter "kisi", but doesnt work together...

推荐答案

如果您序列化的形式,那么你可以添加额外的值,它与 .PARAM()功能

If you serializing the form, then you can add additional values to it with the .param() function

var data = $("#RentForm").serialize() + '&' + $.param({ 'aracid': AracID }, true);

$.ajax({
    type: "POST",
    url: '@Url.Action("Save","AracKirala")',
    data: data,
    ....

这篇关于MVC jQuery的阿贾克斯后返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆