asp.net mvc - Passing specific model from Javascript to MVC Action using Jquery.get() -


I'm having some problems bringing a model back into an MVC action that receives specific models.

This is Javascript code:

  var data filter = {node: 1, name: "John"} $. Get ("MyController / MyAction", {info: dataFilter}, function (data) {$ ("# results") .html (data);});   

This is my MVC model:

  public class MyCommonFilter {public int? Node {get; Set; } Public string name {get; Set; } Public IEnumerable & lt; Int & gt; Get the hierarchy ID { Set; } Public IEnumerable & lt; Int & gt; Receive provider ID { Set; }}   

This is my action:

  Public Function MyAction (MyCommonFilter Info) {...}   

When I try to assume that the value of the "info" parameter is always zero, what is wrong with it? I've read that MVC can detect properties and can convert them to your MyCommonFilter model automatically.

ASP.NET MVC framework can definitely have a powerful type of conclusions, but its For developers, there is no need to sympathize with it.

Your URL and query string are currently your jQuery .get () task:

  / home / massaging? Info [node] = 1 & amp; This is because you are actually sending the following JSON objects:  
  {info: {node: 1, name: "John"}}   

... and asp.net MVC framework almost understands it!


The ASP.NET MVC framework does not require you to provide a parameter name, so if you change the data parameter in your jQuery .get () Should work for!

  $ ("MyController / MyAction", data filter, function (data) {$ ("# result"). Html (info);});   

Example 1: Defined data filter using the object's official (JSON)

  var dataFilter = {node: 1, name : "John"} $ Get ("MyController / MyAction", Datafilters, Functions (Data) {$ ("#come"). Html (Data);});   

Example 2: Define the data filter by using the dynamic properties

  var datafilter = new object () data filter.node = 1 Data filter Name = "john" $ .tet ("mac controller / myaction", data filter, function (data) {$ ("# result"). Html (data);});    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -