Note that there are some explanatory texts on larger screens.

plurals
  1. POGet json data from controller?
    text
    copied!<p>Scripts:</p> <pre><code>&lt;script type="text/javascript"&gt; function getMeterInfo(meter_id) { $.ajax({ url: '@Url.Action("MeterInfo", "Power")', data: { meter_id: meter_id}, dataType: "json", type: "GET", error: function () { alert("Error!"); }, success: function (data) { var item = ""; item += data.sno + " " + data.customer_id + data.city + data.region; //+ more info about meter. $("#meter_info").html(item); } }); } $(document).ready(function () { $("#meters").change(function () { var meter_id = $("#meters").val(); getMeterInfo(meter_id); }); }); &lt;/script&gt; </code></pre> <p><strong>NOTE:</strong> I know content of success function is not correct. I dont know, What Can I write there.</p> <p>cshtml</p> <pre><code>@Html.DropDownList("sno", new SelectList(Model, "sno", "meter_name"), "-- Select Meter --", new { id = "meters" }) &lt;table id=meter_info&gt; &lt;/table&gt; </code></pre> <p>Controller</p> <pre><code> [HttpGet] public ActionResult MeterInfo(string meter_id) { int _meter_id = Int32.Parse(meter_id); var _meter = entity.TblMeters.Where(x =&gt; x.sno == _meter_id).FirstOrDefault(); return Json(_meter, JsonRequestBehavior.AllowGet); } </code></pre> <p>Model</p> <pre><code> public class TblMeters { int sno; int customer_id; string city; string region; ..... } </code></pre> <p>I want to show my model values (sno,customer_id,city,region, etc...) in a html table. When I debug program, Controller action returns expected data.</p> <ol> <li>I dont know How can I show returned data items on table thats name is meter_info.</li> <li>When I run above code, Error function works, not success function.</li> </ol> <p>How can I show data on table? And Why error function works?</p> <p>Thanks.</p>
 

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