My Model -
public class Phasessfilter
{
public string Searchterm {get;set;}
public string ob1 {get;set;}
public string ob2 {get;set;}
public string ob3 {get;set;}
public List<string> ob4 { get; set; }
public List<string> ob5 { get; set; }
}
Controller -
public JsonResult GtRlts(Phasessfilter jop)
{
}
this is my script
var recr = "";
var study = "";
var results = "";
var phases1 = [];
var fund = [];
var values = { Searchterm: Searchterm, ob1: recr, ob2: study, ob3: results, ob4: phases1, ob5: fund }
$.post("GtRlts", values, function (abc) {
}
So i am getting values for Searchterm , ob1 ,ob2 ,ob3 but i am getting null values for ob4 and ob5 .why is List not taking the array values or am i doing something wrong . PS - i dont want to use $.ajax
Change your model to
public class Phasessfilter
{
public string Searchterm {get;set;}
public string ob1 {get;set;}
public string ob2 {get;set;}
public string ob3 {get;set;}
public List<string> ob4 { get; set; }
public List<string> ob5 { get; set; }
public Phasessfilter()
{
ob4 = new List<string>();
ob5 = new List<string>();
}
}
Hey the code written is absolutely fine you just need to test with the values in it and it works just fine.
here is sample Js code
var searchterm = "test1";
var recr = "test2";
var study = "test3";
var results = "test4";
var phases1 = ["Test5","Test6"];
var fund = ["Test6", "Test7"];
debugger;
var values = { Searchterm: searchterm, ob1: recr, ob2: study, ob3: results, ob4: phases1, ob5: fund }
$.post(path + "/Dashboard/Home/GtRlts", values, function (abc) {
});
and the output for a reference rest of the code is same.
You have just define array variable so it get null value
var phases1 = [];
var fund = [];
You have to add items in it:
var phases1 = [1,2];
var fund = [3,4];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.