javascript - How to send a JSON array by route value to the action method (MVC 4) -
i've seen more 30 q&as sending json arrays, have different , strange problem...
i have view represent data jqgrid user. user manipulates rows of , call action method show report based on data. problem must send array route values , can't rid of bad request - invalid url error...
corresponding part of view:
// ... correct codes before var bpics = [], (var = 0; < mydata.length; i++) { var pid = "#chk" + mydata[i].id, sid = "#ddl" + mydata[i].id, pic = { personnelname: mydata[i].personnelname, fathername: mydata[i].fathername, birthdate: mydata[i].birthdate, education: mydata[i].education, universityname: mydata[i].universityname, postname: $(pid).val(), phone: mydata[i].phone, needsettle: $(sid).val() }; bpics.push(pic); } window.open("../rawprint/getburseletterreport/" + json.stringify(bpics) + "/" + $("#txtdestmanname").val() + "/" + $("#ddluniversity").val() + "/" + $("#lblcoursetitle").text()); // ... other correct codes after ... in fact i'm using stimulsoft reports , component dictates developer send variables route values. so, i'm struggling send json string route values (because must...!).
some works i've done:
in web config, added following tags. work when use $.ajax send json array...:
<httpruntime targetframework="4.5" requestpathinvalidcharacters="" requestvalidationmode="2.0" /> and
<pages validaterequest="false"> any help, tip, trick, ... ?!
the json.stringify(bpics) results string
[{personnelname: 'value',$fathername: 'value',birthdate: 'value',...},{personnelname: 'value',$fathername: 'value',birthdate: 'value',...},....]
so actual url format window.open("../rawprint/getburseletterreport/[{personnelname: 'value',$fathername: 'value',birthdate: 'value',...},{personnelname: 'value',$fathername: 'value',birthdate: 'value',...},....]/destmanname/university/coursetitle")
in url having special charector ':' leads invalid url(400 bad request) error
you should pass array value @ end parameter http://yoururl?bpics=json.stringify(bpics); can pass text in parameters wont 400 error if pass special charectors in parameters.
and inside controller write this
public actionresult getburseletterreport(yourclass[] bpics) { .... }
yourclass contains properties personalname, fathername .. public class yourclass { public string personalname{get;set;} .... .... }
Comments
Post a Comment