Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't like to answer with links, nor just text, so here is an example of how can you make a div/table or mostly any html container to change it's content.</p> <p><strong>If you're using MVC with Razor it'd look like this</strong></p> <p><code>TestView.cshtml</code></p> <pre><code>@using (Ajax.BeginForm("Test", "TestController", new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "searchResults" })) { Search User by ID: &lt;input type="text" name="id" /&gt; &lt;input type="submit" value="Search" /&gt; } &lt;table id="searchResults"&gt; &lt;/table&gt; </code></pre> <p><code>TestController.cs</code></p> <pre><code>public class TestController : Controller { public PartialViewResult Test(int id) { var model = myDbContext.Users.Single(q =&gt; q.UserID == id); return PartialView("_PartialViewTest", model); } } </code></pre> <p><code>_PartialViewTest.cshtml</code></p> <pre><code>@model IEnumerable&lt;MyApp.Models.User&gt; &lt;table id="searchResults"&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Email&lt;/th&gt; &lt;/tr&gt; @foreach(var item in Model) { &lt;tr&gt; &lt;td&gt;@item.Name&lt;/td&gt; &lt;td&gt;@item.Email&lt;/td&gt; &lt;/tr&gt; } &lt;/table&gt; </code></pre> <p><strong>...and if you want to do it using classic ASP.NET, it'd be like this:</strong></p> <p><code>TestPage.aspx</code></p> <pre><code>&lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;button type="button" onclick='testCall()'&gt;Test!&lt;/button&gt; &lt;hr /&gt; &lt;div id="ajaxResult"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p><code>Scripts.js / TestPage.aspx</code></p> <pre><code>function testCall() { $.ajax({ url: "TestHandler.ashx", dataType: 'json', success: callbackTestCall }); }; function callbackTestCall(payload) { document.getElementById("ajaxResult").innerHTML = payload; }; </code></pre> <p><code>TestHandler.ashx</code></p> <pre><code>public class TestHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { JavaScriptSerializer jss = new JavaScriptSerializer(); Random random = new Random(); string actualData = random.Next(2001).ToString(); context.Response.ContentType = "text/plain"; context.Response.CacheControl = "no-cache"; context.Response.Write(jss.Serialize(actualData)); } public bool IsReusable { // Whether or not the instance can be used for another request get { return true; } } } </code></pre> <p>If you need further information please, let me know.</p>
    singulars
    1. This table or related slice is empty.
    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. 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