0

ビューからコントローラーにパラメーターを渡そうとしていますが、次のように なります。アクションGetCompanyDataWithIdを実行しようとすると、値をnullにすることはできません。

実行が成功すると、パラメーターがコントローラーに渡され、jqGridの入力に使用されるJSONデータが返されます。


値が適切に渡されていないようです何かアイデアはありますか?

$("#dropdwnlist").change(function () {
               var value = $(this).val();

               $.ajax({
                   url: '<%= Url.Action("GetCompanyDataWithId", "Billing") %>', 
                   type: "POST",                            
                   data: { companyid: "25" },
                   success: function (data) {
                       alert(data);
                       $('#Bgrid').setGridParam({ url: '<%= Url.Action("GetCompanyDataWithId", "Billing") %>'});
                       $('#Bgrid').trigger('reloadGrid');                                                    
                   },
                   error: function(xhr, ajaxOptions, thrownError) {
                        alert(xhr.responseText);
                   }

               }).done(function (msg) {
                   alert("Data Saved: " + msg);
               });
           });
4

1 に答える 1

1

コントローラメソッドが次のようになっていると仮定します。

public ActionResult GetCompanyDataWithId(string companyid) {}

$.ajax次のオプションを使用できます。

data: JSON.stringify({ companyid: "25" }),
type: 'post',
dataType: 'json',
contentType: 'application/json; charset=utf-8',

またはもっと簡単:

Url.Action("GetCompanyDataWithId", "Billing", new { companyid = "25" })
于 2013-02-11T19:39:17.013 に答える