public class Tuner
{
public string Tick1 { get; set; }
public string Tick2 { get; set; }
public List<Sections> Sections { get; set; }
//public Sections[] Sections { get; set; }
}
public class Sections
{
public string Section { get; set; }
public string LI { get; set; }
}
see my action is expecting two parameter. one is Tuner sdata and other one is string status
when i am sending Tuner data from ajax then it is working but when i add value for status then fail. tell me how could i pass multiple parameter value from ajax to mvc action.
my question was totally different. i want to pass my js array and one string parameter to action. which i try but fail and seen action is not getting call.
Member
77 Points
150 Posts
How to pass multiple parameter to mvc action
Jul 03, 2020 06:04 AM|TDP|LINK
see my code
MVC action
see my action is expecting two parameter. one is Tuner sdata and other one is string status
when i am sending Tuner data from ajax then it is working but when i add value for status then fail. tell me how could i pass multiple parameter value from ajax to mvc action.
All-Star
120166 Points
27994 Posts
Moderator
MVP
Re: How to pass multiple parameter to mvc action
Jul 03, 2020 08:25 AM|ignatandrei|LINK
For MVC, this is the reference for me: https://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/
Please show the
value
Member
77 Points
150 Posts
Re: How to pass multiple parameter to mvc action
Jul 03, 2020 10:37 AM|TDP|LINK
my question was totally different. i want to pass my js array and one string parameter to action. which i try but fail and seen action is not getting call.
All-Star
53001 Points
23587 Posts
Re: How to pass multiple parameter to mvc action
Jul 03, 2020 10:43 AM|mgebhard|LINK
Either add "status" to the Tuner model, add status to the url, or add status to the post parameters.
Added to the URL
var status = "new"; $.ajax({ url: '@Url.Action("Test1")?status=' + status, type: "POST", contentType: "application/json; charset=utf-8", data: JSON.stringify(Tuner), success: function (result) { console.log(result); }, error: function (result) { console.log("Failed"); } });
Add to post collection
var Tuner = {}; Tuner.Tick1 = 'true'; Tuner.Tick2 = 'false'; Tuner.Sections = []; var Section_LI = {}; Section_LI.Section='Consensus Model'; Section_LI.LI = 'Operating Earnings Before Income Taxes'; Tuner.Sections.push(Section_LI); Section_LI = {}; Section_LI.Section='Consensus Model'; Section_LI.LI = 'Net Income attributable to common, GAAP'; Tuner.Sections.push(Section_LI); data = { tuner: Tuner, status: "new" }; var status = "new"; $.ajax({ url: '@Url.Action("Test1")', type: "POST", contentType: "application/json; charset=utf-8", data: JSON.stringify(data), success: function (result) { console.log(result); }, error: function (result) { console.log("Failed"); } });
All-Star
20953 Points
4984 Posts
Re: How to pass multiple parameter to mvc action
Jul 03, 2020 01:59 PM|asteranup|LINK
try this-
Anup Das Gupta
Visit My Blog
You can also connect with me in LinkedIn