Aktion „Array von Objekten an .NET-Controller senden“.C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Aktion „Array von Objekten an .NET-Controller senden“.

Post by Anonymous »

Ich versuche, ein Javascript-Array von Objekten an einen .NET-Controller-Aktionsparameter List zu übergeben. Unten ist mein C#

Code: Select all

public bool ImportACE([FromBody] List elements)
{
foreach(Element e in elements)
{
uint srcAddrInt = ConvertIpAddressToUInt(e.SRC_Addr);
Console.WriteLine($"The IP address {e.SRC_Addr} as an integer is: {srcAddrInt}");
}

return true;
}
Unten ist die Variable, die ich übergebe, und der Ajax-Aufruf

Code: Select all

importData.push({
ACLId: 11,
DeviceId: 2,
ACLGroupId: 5,
ProtocolId: 27,
LiftDate: liftDate,
ActionDate: actionDate,
RemedyTckt: remedyTicket,
ITSMTckt: itsmTicket,
/* CommandView: cleanCmdVar,*/
SRC_Addr: srcAddr,
SRC_Mask: "0.0.0.0",
DST_Addr: "0.0.0.0",
DST_Mask: "255.255.255.255",
ArinInfo: arin,
FlagLogInput: 1,
FlagLog: 0,
Active: 0
});

var jsonData = JSON.stringify(importData);

$.ajax({
url: '/GAM/ACE/Import',
type: 'POST',
data: jsonData,
contentType: "application/json; charset=utf-8",
success: function (result) {
if (result) {
$('#loading-overlay').fadeOut();
} else {
alert("Error. Import unsuccessful.");
$('#loading-overlay').fadeOut();
}
},
error: function (jqXHR, textStatus, errorThrown) {
$('#loading-overlay').fadeOut();
alert("Unable to import data.  Error with /GAM/ACE/ImportAce ." + errorThrown);;
}
});
Hier ist das Modell, es ist ziemlich groß

Code: Select all

 public class Element
{
[Required]
public int ElementId { get; set; }
public int DeviceId { get; set; }
public string Device { get; set; }
public int ACLId { get; set; }
public string ACL { get; set; }
public int ACLGroupId { get; set; }
public string ACLGroup { get; set; }
public int SequenceNum { get; set; }
public int ActionId { get; set; }
public bool PermitBool { get; set; }
public bool DenyBool { get; set; }
public string Action { get; set; }
public string Protocol { get; set; }
public int ProtocolId { get; set; }
public string SRC_Addr { get; set; }
public string SRC_Addr_Int { get; set; }
public string SRC_Mask { get; set; }
public string SRC_Mask_Int { get; set; }
public string SRC_OP { get; set; }
public string SRC_B_Range { get; set; }
public string SRC_E_Range { get; set; }
public string DST_Addr { get; set; }
public string DST_Addr_Int{ get; set; }
public string DST_Mask { get; set; }
public string DST_Mask_Int { get; set; }
public string DST_OP { get; set; }
public string DST_B_Range { get; set; }
public string DST_E_Range { get; set; }
public int FlagLog { get; set; }
public int FlagLogInput { get; set; }
public bool FlagLogBool { get; set; }
public bool FlagLogInputBool { get; set; }
public bool FlagTCPEst { get; set; }
public bool FlagTCPAck { get; set; }
public bool FlagTCPFin { get; set; }
public bool FlagTCPPsh { get; set; }
public bool FlagTCPRst { get; set; }
public bool FlagTCPSyn { get; set; }
public bool FlagTCPUrg { get; set; }
public int ICMPType { get; set; }
public string ICMPCode { get; set; }
public string ICMPMessage { get; set; }
public int IGMPType { get; set; }
public int FlagPrecedence { get; set; }
public string Precedence { get; set; }
public int TOSId{ get; set; }
public int FlagDSCP { get; set; }
public string DSCP { get; set; }
public int FlagFragments { get; set; }
public int DynamicTimeOut { get; set; }
public string DynamicName { get; set; }
public string TimeRangeName { get; set; }
public int FlagEvaluate { get; set; }
public string EvaluateAcl { get; set; }
public string ReflexiveAcl { get; set; }
public int ReflexiveTimeout { get; set; }
public string Remark { get; set; }
public string CommandView { get; set; }
public DateTime? LiftDate { get; set; }
public DateTime? ActionDate { get; set; }
public string RemedyTckt { get; set; }
public string ITSMTckt { get; set; }
public string ArinInfo { get; set; }
public int UserId { get; set; }
public DateTime AclTime { get; set; }
public bool Active { get; set; }
public bool Locked { get; set; }
public bool Permanent { get; set; }
public int Special { get; set; }
public int CMDType { get; set; }
public int CMDOther { get; set; }
public DateTime Modified { get; set; }
public DateTime Created { get; set; }
public long AuthorEDIPI { get; set; }
public long EditorEDIPI { get; set; }
public string Editor {  get; set; }
public string LogOptionId { get; set; }
}
Ich bin mir nicht sicher, was ich falsch mache. Der Elementparameter für den Controller wird empfangen und zeigt die Objekte in der Liste an. Die Werte jedes Objekts sind jedoch null. Es kommen keine Daten durch. Ich kann sehen, dass die Nutzlast korrekt durchkommt. Alle Vorschläge sind willkommen

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post