我想将对象传递给控制器操作,但它不起作用。对象为空,没有错误。我调试了它,我得到了传递的参数。
脚本
$(document).ready(function () {
var IrregularChartParams = {
MeterId: 2,
MeterTypeId: 2,
ReadingTypeId: 4,
StartDate: "start",
EndDate: "end",
DateRangeId: 5
};
var chartParams= JSON.stringify(IrregularChartParams);
$.ajax({
type: "POST",
url: app_base_url + 'Graph/GetChart',
contentType: "application/json;charset=utf-8",
dataType: "json",
data: chartParams,
traditional: true,
success: function (result) {
$("#chart").html(result);
},
error: function () {
alert("hatalı");
}
});
});
控制器
public ActionResult _IrregularChart(IrregularChartParams chartParams)
{
// chartParams is null
}
调试时间参数如下所示:
- 参数 {%7b%22MeterId%22%3a2%2c%22MeterTypeId%22%3a2%2c%22ReadingTypeId%22%3a4%2c%22StartDate%22%3a%22start%22%2c%22EndDate%22%3a%22end%22 %2c%22DateRangeId%22%3a5%7d&漏斗网=44D66957AF9E021D68F011F7EA89CF99585363E067264B4A9B2B60FB51030DFA64EAA943529D3352875332394F24293162CBFE088352F1169202E0806155F66F370237D16A787AB8E76417B72808F34FEC9B5133D1D56D0839B614F2E231AB8DE23FE3BB7C048BAA3FCEEDABD4A2A6ACCB1D76DEB657B3B8575A664823DA24044F67C096206D04CBD5971BAE21684EA3FE2CAA747A1C8C563692DBE6335A0948&.ASPXAUTH=C42E113D8E4C49775DE2172054A1D505B777F691EEDA493FBD1B982148F59ECB28D730ED46E19F8BD3AF7A37046D73D462907AF535ED2DC3F80CD6B9681717D9DAD7BD919FAA8BD57B5C7A6EACC0E0EDE956004762C1BD2E76F9D26B9C4036B0A4C903DC02BCFEE341151D6E0A35D748CE4D4FB3C1B84FF58A196E85F78477DF&ALL_HTTP=HTTP_CONNECTION%3akeep-alive%0d%0aHTTP_CONTENT_LENGTH%3a99%0d%0aHTTP_CONTENT_TYPE%3aapplication%2fx-www-form-urlencoded%3b+charset%3dUTF-8%0d%0aHTTP_ACCEPT%3a*%2f* %0d%0aHTTP_ACCEPT_CHARSET%3aISO-8859-9%2cutf-8%3bq%3d0.7%2c*%3bq%3d0。3%0d%0aHTTP_ACCEPT_ENCODING%3agzip%2cdeflate%2csdch%0d%0aHTTP_ACCEPT_LANGUAGE%3atr-TR%2ctr%3bq%3d0.8%2cen-US%3bq%3d0.6%2cen%3bq%3d0.4%0d%0aHTTP_COOKIE% 3aFunnelWeb%3d44D66957AF9E021D68F011F7EA89CF99585363E067264B4A9B2B60FB51030DFA64EAA943529D3352875332394F24293162CBFE088352F1169202E0806155F66F370237D16A787AB8E76417B72808F34FEC9B5133D1D56D0839B614F2E231AB8DE23FE3BB7C048BAA3FCEEDABD4A2A6ACCB1D76DEB657B3B8575A664823DA24044F67C096206D04CBD5971BAE21684EA3FE2CAA747A1C8C563692DBE6335A0948%3b+.ASPXAUTH%3dC42E113D8E4C49775DE2172054A1D505B777F691EEDA493FBD1B982148F59ECB28D730ED46E19F8BD3AF7A37046D73D462907AF535ED2DC3F80CD6B9681717D9DAD7BD919FAA8BD57B5C7A6EACC0E0EDE956004762C1BD2E76F9D26B9C4036B0A4C903DC02BCFEE341151D6E0A35D748CE4D4FB3C1B84FF58A196E85F78477DF%0d%0aHTTP_HOST%3alocalhost%3a50305%0d%0aHTTP_REFERER%3ahttp%3a%2f%2flocalhost%3a50305%2fGraph%0d%0aHTTP_USER_AGENT%3aMozilla%2f5.0+(Windows+NT+6.1)+AppleWebKit%2f537. 22+(KHTML%2c+like+Gecko)+Chrome%2f25.0.1364.172+Safari%2f537.22%0d%0aHTTP_ORIGIN%3ahttp%3a%2f%2flocalhost%3a50305%0d%0aHTTP_X_REQUESTED_WITH%3aXMLHttpRequest%0d%0a&ALL_RAW=连接%3a+保持活动状态%0d%0aContent-Length%3a+99%0d%0aContent-Type%3a+application%2fx-www-form-urlencoded%3b+charset%3dUTF-8%0d%0aAccept%3a+172+Safari%2f537.22%0d%0aHTTP_ORIGIN%3ahttp%3a%2f%2flocalhost%3a50305%0d%0aHTTP_X_REQUESTED_WITH%3aXMLHttpRequest%0d%0a&ALL_RAW=Connection%3a+keep-alive%0d%0aContent-Length%3a+99% 0d%0aContent-Type%3a+application%2fx-www-form-urlencoded%3b+charset%3dUTF-8%0d%0aAccept%3a+172+Safari%2f537.22%0d%0aHTTP_ORIGIN%3ahttp%3a%2f%2flocalhost%3a50305%0d%0aHTTP_X_REQUESTED_WITH%3aXMLHttpRequest%0d%0a&ALL_RAW=Connection%3a+keep-alive%0d%0aContent-Length%3a+99% 0d%0aContent-Type%3a+application%2fx-www-form-urlencoded%3b+charset%3dUTF-8%0d%0aAccept%3a+%2f%0d%0aAccept-Charset%3a+ISO-8859-9%2cutf-8%3bq%3d0.7%2c*%3bq%3d0.3%0d%0aAccept-Encoding%3a+gzip%2cdeflate%2csdch%0d% 0aAccept-Language%3a+tr-TR%2ctr%3bq%3d0.8%2cen-US%3bq%3d0.6%2cen%3bq%3d0.4%0d%0aCookie%3a+FunnelWeb%3d44D66957AF9E021D68F011F7EA89CF99585363E067264B4A9B2B60FB51030DFA64EAA943529D3352875332394F24293162CBFE088352F1169202E0806155F66F370237D16A787AB8E76417B72808F34FEC9B5133D1D56D0839B614F2E231AB8DE23FE3BB7C048BAA3FCEEDABD4A2A6ACCB1D76DEB657B3B8575A664823DA24044F67C096206D04CBD5971BAE21684EA3FE2CAA747A1C8C563692DBE6335A0948%3b+.ASPXAUTH%3dC42E113D8E4C49775DE2172054A1D505B777F691EEDA493FBD1B982148F59ECB28D730ED46E19F8BD3AF7A37046D73D462907AF535ED2DC3F80CD6B9681717D9DAD7BD919FAA8BD57B5C7A6EACC0E0EDE956004762C1BD2E76F9D26B9C4036B0A4C903DC02BCFEE341151D6E0A35D748CE4D4FB3C1B84FF58A196E85F78477DF%0d%0aHost%3a+localhost%3a50305%0d%0aReferer%3a+http%3a%2f%2flocalhost%3a50305%2fGraph%0d%0aUser-Agent%3a+Mozilla%2f5.0+(Windows+NT +6.1)+AppleWebKit%2f537.22+(KHTML%2c+like+Gecko)+Chrome%2f25.0.1364.172+Safari%2f537.22%0d%0aOrigin%3a+http%3a%2f%2flocalhost%3a50305% 0d%0aX-Requested-With%3a+XMLHttpRequest%0d%0a&APPL_MD_PATH=&APPL_PHYSICAL_PATH=C%3a%5cUsers%5cariza%5cDesktop%5cMasa%u00fcst%u00fc%5cosos_plus_2%5cOsos-21.11.2012%5cOsosPlus2.UI%5cOsosPlus2.% 5c&AUTH_TYPE=表格&AUTH_USER=KIPA&AUTH_PASSWORD=&LOGON_USER=CTS%5cariza&REMOTE_USER=KIPA&CERT_COOKIE=&CERT_FLAGS=&CERT_ISSUER=&CERT_KEYSIZE=&CERT_SECRETKEYSIZE=&CERT_SERIALNUMBER=&CERT_SERVER_ISSUER=&CERT_SERVER_SUBJECT=&CERT_SUBJECT=&CONTENT_LENGTH=99&CONTENT_TYPE=application%2fx-www-form-urlencoded%3b+charset%3dUTF-8&GATEWAY_INTERFACE=&HTTPS=&HTTPS_KEYSIZE=&HTTPS_SECRETKEYSIZE=&HTTPS_SERVER_ISSUER=&HTTPS_SERVER_SUBJECT= &INSTANCE_ID=&INSTANCE_META_PATH=&LOCAL_ADDR=%3a%3a1&PATH_INFO=%2fGraph%2f_IrregularChart&PATH_TRANSLATED=C%3a%5cUsers%5cariza%5cDesktop%5cMasa%u00fcst%u00fc%5cosos_plus_2%5cOsos-21.11.12.2012%c%5cOs2.osPlusUI%5cOsos-21.11.2012%c%5cOs2.os 5c_IrregularChart&QUERY_STRING=&REMOTE_ADDR=%3a%3a1&REMOTE_HOST=%3a%3a1&REMOTE_PORT=&REQUEST_METHOD=POST&SCRIPT_NAME=%2fGraph%2f_IrregularChart&SERVER_NAME=localhost&SERVER_PORT=50305&SERVER_PORT_SECURE=0&SERVER_PROTOCOL=HTTP%2f1.1&SERVER_SOFTWARE=&URL=%2fGraph%2f_IrregularChart&HTTP_CONNECTION=keep-alive&HTTP_CONTENT_LENGTH=99&HTTP_CONTENT_TYPE=application%2fx-www-form-urlencoded%3b+charset%3dUTF-8&HTTP_ACC%2f&HTTP_ACCEPT_CHARSET=ISO-8859-9%2cutf-8%3bq%3d0.7%2c*%3bq%3d0.3&HTTP_ACCEPT_ENCODING=gzip%2cdeflate%2csdch&HTTP_ACCEPT_LANGUAGE=tr-TR%2ctr%3bq%3d0.8%2cen-US%3bq %3d0.6%2cen%3bq%3d0.4&HTTP_COOKIE=FunnelWeb%3d44D66957AF9E021D68F011F7EA89CF99585363E067264B4A9B2B60FB51030DFA64EAA943529D3352875332394F24293162CBFE088352F1169202E0806155F66F370237D16A787AB8E76417B72808F34FEC9B5133D1D56D0839B614F2E231AB8DE23FE3BB7C048BAA3FCEEDABD4A2A6ACCB1D76DEB657B3B8575A664823DA24044F67C096206D04CBD5971BAE21684EA3FE2CAA747A1C8C563692DBE6335A0948%3b+.ASPXAUTH%3dC42E113D8E4C49775DE2172054A1D505B777F691EEDA493FBD1B982148F59ECB28D730ED46E19F8BD3AF7A37046D73D462907AF535ED2DC3F80CD6B9681717D9DAD7BD919FAA8BD57B5C7A6EACC0E0EDE956004762C1BD2E76F9D26B9C4036B0A4C903DC02BCFEE341151D6E0A35D748CE4D4FB3C1B84FF58A196E85F78477DF&HTTP_HOST=localhost%3a50305&HTTP_REFERER=http%3a%2f%2flocalhost%3a50305%2fGraph&HTTP_USER_AGENT=Mozilla%2f5.0+(Windows+NT+6.1)+AppleWebKit%2f537.22+(KHTML%2c+like+Gecko)+Chrome%2f25.0.1364。 172+Safari%2f537.22&HTTP_ORIGIN=http%3a%2f%2flocalhost%3a50305&HTTP_X_REQUESTED_WITH=XMLHttpRequest} System.Collections.Specialized.NameValueCollection {System.Web.HttpValueCollection}
为什么控制器中的对象为空,为什么参数看起来像上面那样?
更新
DTO
public class IrregularChartParams
{
public int MeterId { get; set; }
public int MeterTypeId { get; set; }
public int ReadingTypeId { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int DateRangeId { get; set; }
}
在它工作之前,然后我更改属性名称,而不是它不起作用......
谢谢。