Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.net MVC3, C#, Figure out Single or Multiple Json paramter?
    primarykey
    data
    text
    <p>I'm passing to single JSON type parameter and multiple JSON type parameters to Asp.Net.</p> <p>and in Asp.Net, I need to figure out the parameter is single data or multiple data to update DB (EF, Repository pattern).</p> <p>[Single]</p> <p><img src="https://i.stack.imgur.com/TgEHe.png" alt="enter image description here"></p> <p>[Multiple]</p> <p><img src="https://i.stack.imgur.com/mfi9k.png" alt="enter image description here"></p> <p>Firstly, I tried like this,</p> <pre><code>[HttpPost] public ActionResult ItemUpdate(WEBORDERLN ln ,IList&lt;WEBORDERLN&gt; lns) { </code></pre> <p><strong>but it comes to ln always. it never go to lns :(</strong></p> <pre><code>[HttpPost] public ActionResult ItemUpdate(WEBORDERLN ln) { // it works for only single update </code></pre> <p>and </p> <pre><code>[HttpPost] public ActionResult ItemUpdate(IList&lt;WEBORDERLN&gt; lns) { // it works for only multiple update </code></pre> <p>How I figure out, the JSON type parameter is single or multiple?</p> <p>anybody know, please advice me.</p> <p>Thank you!</p> <p>[EDIT]</p> <p><img src="https://i.stack.imgur.com/7mGBw.png" alt="enter image description here"></p> <pre><code>[HttpPost] public ActionResult ItemUpdate(WEBORDERLNS lns) { try { EFWebOrderLnRepository webOrderLn = new EFWebOrderLnRepository(); log.Debug("Count : "+lns.lns.Count.ToString()); // Object reference not set to an instance of an object. log.Debug(lns.lns.Count()); //null, error : Value cannot be null log.Debug(lns.lns.Count().ToString()); //null, error : Value cannot be null foreach (WEBORDERLN ln in lns.lns) { webOrderLn.updateWebOrderLn(ln); // Error : Object reference not set to an instance of an object } . . . public class WEBORDERLNS { public IList&lt;WEBORDERLN&gt; lns { get; set; } } </code></pre> <p>[EDIT]</p> <pre><code>Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.5 Connection keep-alive Content-Length 875 Content-Type application/json; charset=UTF-8 Cookie user=38C6C07684B04645821CA5273EAB5B34340CE8CCA13A7D67DC748819B02C6963E4AD2A322068FC3090D3FE03EC81E663A5DED6FF2534E2595B40CF57EFF9BB544FFAC95CD79020E8A94019A3DC53B769EFC4049B6B9627E98AD9DBC1431BB5D99A47625B3353FA697A1CC005855C0248E95F61F7BD4A5362D75E5D01B395FB14E078524B8D0C7219AF959F9AED188AB30A16187DE166D5BD008B0013A65D470C52C9408C47FD42672B8FBABDB3524F77 Host localhost:49995 Referer http://localhost:49995/ User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1 X-Requested-With XMLHttpRequest </code></pre> <p>[EDIT]</p> <p><img src="https://i.stack.imgur.com/z1olO.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload