Mvc Jquery Ajax Post 返回 null [英] Mvc Jquery Ajax Post returns null

查看:38
本文介绍了Mvc Jquery Ajax Post 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试发布两个参数...这是ajax代码

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 正确地发布了aracid",但是当方法被触发时kisi"变成了空...我尽量不将aracid"与kisi"一起发布,因此ajax为一个参数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 Ajax Post 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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