Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向action MVC jquery发布更多参数_Jquery_Asp.net Mvc_Asp.net Mvc 5 - Fatal编程技术网

如何向action MVC jquery发布更多参数

如何向action MVC jquery发布更多参数,jquery,asp.net-mvc,asp.net-mvc-5,Jquery,Asp.net Mvc,Asp.net Mvc 5,我想为YeniKayit操作发布三个参数。我可以发第一张。但当我发布第二条时,我得到一个错误: 参数字典包含不可为null类型的参数“koyid”的null条目 YeniKayit行动: jQuery代码: $('select[name=MahalleId]').change(function () { var id = $(this).val(); $.post('@Url.Action("YeniKayit")/?mahalleid=' + id)

我想为YeniKayit操作发布三个参数。我可以发第一张。但当我发布第二条时,我得到一个错误:

参数字典包含不可为null类型的参数“koyid”的null条目

YeniKayit行动:

jQuery代码:

$('select[name=MahalleId]').change(function () {
        var id = $(this).val();
        $.post('@Url.Action("YeniKayit")/?mahalleid=' + id)
      });
    $('select[name=Koy]').change(function () {
        var id = $(this).val();
        $.post('@Url.Action("YeniKayit")/&koyid=' +id)

    }); 
    $('select[name=afettur]').change(function () {
        var afetid = $(this).val();
        $.post('@Url.Action("YeniKayit")/&afetturid=' + afetid)

    });
MahalleId对象:

阿菲图尔物体:


您的第二个查询字符串似乎是错误的

尝试一下:

//change 
$.post('@Url.Action("YeniKayit")/&koyid=' +id);
//to 
$.post('@Url.Action("YeniKayit")?koyid=' +id);
要进行故障排除,您应该实现.post函数的错误功能,如下所示:

$.post('@Url.Action("YeniKayit")/&koyid=' +id)
  .error(function(responseObject){
   /*the object signature looks like this:
     responseObject= 
     {
       readyState:n
       ,responseText:"server response"
       , status:"http status code"
       , statusText:"the meaning of the status code"
     }
   */
});

这里有一个很好的资源:

您需要$.post'@Url.ActionYeniKayit,{koyid:someValue,mahalleid:anotherValue,afetturid:anotherValue}但是为什么你有一个参数Afet model-这毫无意义-并且你不能使用$.post发布一个文件,所以不清楚为什么你也有这个参数我使用model作为另一个进程将model的值插入数据库,除非你的模型包含属性koyid,mahalleid和afetturid-在这种情况下,您可以删除所有其他参数-然后删除它。相反,在方法-var model=new Afet中初始化一个新实例;你只需要说一个值,另一个值。MahalleId、Koy、afettur都是selectdropdown。例如,如果我将$'select[name=Koy].val放置到而不是someValue,它是否有效?@StephenMueckeYes,但为什么要使用$'select[name=Koy].val?它应该是$'Koy'。valInfact,这正是我现在想要做的。首先,当我将select object的名称更改为KoyId是数据库中的Column name时,它工作正常。我想检查用户是否选择了任何选项。然后我尝试了你的代码。事实上,我不明白我应该做什么
<select name="Koy" class="form-control" data-val="true" 
        data-val-required="Köy alanı boş bırakılamaz">
</select>
@Html.ValidationMessageFor(model => model.Koy.KoyId, string.Empty, new { @class = "text-danger" })
@Html.DropDownList("afettur", ViewData["Türler"] as SelectList, "-- Tür Seçiniz --", new { style = "width:250px", @class = "form-control" })
//change 
$.post('@Url.Action("YeniKayit")/&koyid=' +id);
//to 
$.post('@Url.Action("YeniKayit")?koyid=' +id);
$.post('@Url.Action("YeniKayit")/&koyid=' +id)
  .error(function(responseObject){
   /*the object signature looks like this:
     responseObject= 
     {
       readyState:n
       ,responseText:"server response"
       , status:"http status code"
       , statusText:"the meaning of the status code"
     }
   */
});