Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>Request.InputStream</code> allows you to access the raw request data. If this data is formatted using some standard format such as <code>application/x-www-form-urlencoded</code> or <code>multipart/form-data</code> or some other format that the default model binder understands you do not need to use <code>Request.InputStream</code>. ASP.NET will parse the request values and you will be able to access them directly using <code>Request[...]</code>. Of course in ASP.NET MVC you don't even need to use <code>Request[...]</code> because you can define a view model which your controller action will take as parameter and leave the model binder assign its properties from the request.</p> <p>There are cases though when you might want to access the raw request stream. For example you have invented some custom protocol and the client sends some custom formatted data in the request stream. Those cases are very rare since inventing custom protocols is not very common.</p> <p>Now back to your question. In your case you could define a view model:</p> <pre><code>public class MyViewModel { public string SomeData { get; set; } } </code></pre> <p>which your controller action will take as argument:</p> <pre><code>public ActionResult GetSomeData(MyViewModel model) { // model.SomeData will contain the Hello string that the client sent return Json("something"); } </code></pre> <p>and on the client I would recommend you using the <code>JSON.stringify</code> method which is natively built into modern browsers to JSON serialize the request javascript literal into a JSON string instead of manually writing the JSON as you did:</p> <pre><code>$.ajax({ type: 'POST', url: 'Home/GetSomeData', data: JSON.stringify({ someData: 'Hello' }), contentType: 'application/json; charset=utf-8', success: function (msg) { alert(msg); // Insert the returned HTML into the &lt;div&gt;. $('#dvResult').html(msg); } }); </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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